Reputation: 47
I have problem about nodejs + mongodb findandmodify() function, last week the code below was running ok, but suddenly now it throw error:
db.collection(collectionName).findAndModify(query || {}, [], {$set: object},
{upset: true}, callback || function () {
});
if query is undefined that code run ok, but query params ex: "_id": "idofcollection", or "template": "templatename" it throw an exception:
E:\Working\Projects\iERP\trunk\client\source\node_modules\mongodb\lib\db.js:309
handleCallback(callback, null, result.result);
^TypeError: Cannot read property 'result' of undefined
at E:\Working\Projects\iERP\trunk\client\source\node_modules\mongodb\lib\db.js:309:42
at E:\Working\Projects\iERP\trunk\client\source\node_modules\mongodb-core\lib\connection\pool.js:436:18
at doNTCallback0 (node.js:419:9)
at process._tickCallback (node.js:348:13)
Please explain for me way to solve this problem?
Upvotes: 0
Views: 725
Reputation: 6403
I would use $or
instead:
db.collection(collectionName).findAndModify({ $or: [ query, { example: 10 } ] }, {$set: object}, function (){
});
Two things:
callback
was in your code. Usually a callback is an anonymous function.query
should look something like this { price: 5 }
Here is some documentation of $or
: https://docs.mongodb.com/manual/reference/operator/query/or/
Hope this helps!
Upvotes: 1