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:
parent
d52f9dcd30
commit
1e31652073
@ -106,7 +106,8 @@
|
|||||||
<p>Insert will insert a new object.</p>
|
<p>Insert will insert a new object.</p>
|
||||||
<p>Save and insert either store <code>msg</code> or <code>msg.payload</code>.</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>
|
<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>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
|
<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>
|
<i>all of the objects</i> in the collection.</p>
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
module.exports = function(RED) {
|
module.exports = function(RED) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var mongo = require('mongodb');
|
var mongo = require('mongodb');
|
||||||
|
var ObjectID = require('mongodb').ObjectID;
|
||||||
var MongoClient = mongo.MongoClient;
|
var MongoClient = mongo.MongoClient;
|
||||||
|
|
||||||
function MongoNode(n) {
|
function MongoNode(n) {
|
||||||
@ -136,7 +137,9 @@ module.exports = function(RED) {
|
|||||||
upsert: node.upsert,
|
upsert: node.upsert,
|
||||||
multi: node.multi
|
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) {
|
coll.update(query, payload, options, function(err, item) {
|
||||||
if (err) {
|
if (err) {
|
||||||
node.error(err,msg);
|
node.error(err,msg);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-mongodb",
|
"name" : "node-red-node-mongodb",
|
||||||
"version" : "0.0.7",
|
"version" : "0.0.8",
|
||||||
"description" : "Node-RED nodes to talk to an Mongo database",
|
"description" : "Node-RED nodes to talk to an Mongo database",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"mongodb" : "^2.2.5"
|
"mongodb" : "^2.2.11"
|
||||||
},
|
},
|
||||||
"repository" : {
|
"repository" : {
|
||||||
"type":"git",
|
"type":"git",
|
||||||
|
Loading…
Reference in New Issue
Block a user