mongodb javascript更新 [英] mongodb javascript update

查看:79
本文介绍了mongodb javascript更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从JS更新mongodb集合?

How do I update a mongodb collection from JS?

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

我这样做了吗?我需要使用$ set吗?

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

基本上内容是一个json对象,它应该替换找到的文件。

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

谢谢。

我正在使用mongodb节点本机驱动程序。

I'm using the mongodb node native driver.

推荐答案

如果您想要替换文档,那么您正在做正确的事情。如果要更新现有文档的字段,则应使用$ set。

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.

请参阅此处: http://www.mongodb.org/display/DOCS/Updating

这篇关于mongodb javascript更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆