开发者

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 sh开发者_运维知识库ould replace the document that's found.

Thanks.

I'm using the mongodb node native driver.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜