Quantcast
Channel: Update on MongoDB from NodeJS doesnt work - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Update on MongoDB from NodeJS doesnt work

$
0
0

I am able to run the following update command from command line:

db.Camera.update({_id:ObjectId("51059ca49c7b280809a2a81e")}, {$set: {"Selected":0}});

But the following code in NodeJS doesnt work. When I log item.Selected, I get a non-zero value.

exports.findById = function(req, res) {    var ids = req.params.id.split(",");    db.collection('Camera', function(err, collection) {        for(var i = 0; i < ids.length; i++){            collection.findOne({'_id':idArray[i]}, function(err, item) {                item.Selected += 1;                console.log('Selected: '+ item.Selected);                collection.update({'_id':new BSON.ObjectID(ids[i])}, item,function(err, updated) {                  if( err || !updated ) console.log("Not updated");                  else console.log("Updated");                });            });        }    });};

In the console, I always see "Not updated".

Thanks for your help.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images