1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Better handling of mongo ObjectId for updates

This commit is contained in:
Dave Conway-Jones 2016-11-02 15:25:35 +00:00
parent d52f9dcd30
commit 1e31652073
3 changed files with 8 additions and 4 deletions

View File

@ -106,7 +106,8 @@
<p>Insert will insert a new object.</p>
<p>Save and insert either store <code>msg</code> or <code>msg.payload</code>.</p>
<p>Update will modify an existing object or objects. The query to select objects to update uses <code>msg.query</code>
and the update to the element uses <code>msg.payload</code>.</p>
and the update to the element uses <code>msg.payload</code>. If <code>msg.query._id</code> is
a valid mongo ObjectId string it will be converted to an ObjectId type.</p>
<p>Update can add a object if it does not exist or update multiple objects.</p>
<p>Remove will remove objects that match the query passed in on <code>msg.payload</code>. A blank query will delete
<i>all of the objects</i> in the collection.</p>

View File

@ -17,6 +17,7 @@
module.exports = function(RED) {
"use strict";
var mongo = require('mongodb');
var ObjectID = require('mongodb').ObjectID;
var MongoClient = mongo.MongoClient;
function MongoNode(n) {
@ -136,7 +137,9 @@ module.exports = function(RED) {
upsert: node.upsert,
multi: node.multi
};
if (ObjectID.isValid(msg.query._id)) {
msg.query._id = new ObjectID(msg.query._id);
}
coll.update(query, payload, options, function(err, item) {
if (err) {
node.error(err,msg);

View File

@ -1,9 +1,9 @@
{
"name" : "node-red-node-mongodb",
"version" : "0.0.7",
"version" : "0.0.8",
"description" : "Node-RED nodes to talk to an Mongo database",
"dependencies" : {
"mongodb" : "^2.2.5"
"mongodb" : "^2.2.11"
},
"repository" : {
"type":"git",