Mark
Mark

Reputation: 33671

mongodb javascript update

How do I update a mongodb collection from JS?

db.collection('fruits', function (err, collection) {
    collection.update({ "_id": content.fruitID}, content, function () {
    });
});

Am I doing this right? DO I need to use $set?

Basically content is a json object that should replace the document that's found.

Thanks.

I'm using the mongodb node native driver.

Upvotes: 4

Views: 8307

Answers (1)

Bernie Hackett
Bernie Hackett

Reputation: 8909

If you want to replace the document you're doing the right thing. If you want to update a field of the existing document you should use $set.

See here: http://www.mongodb.org/display/DOCS/Updating

Upvotes: 2

Related Questions