在Mongodb中,如何将值推入数组?

时间:2011-08-25 09:11:28

标签: mongodb database

假设我的文件是这样的:

{ names: ['jacob','jessie','andrew'] }

我想把“michael”推到所有文件中。我该怎么做?

2 个答案:

答案 0 :(得分:3)

db.mycol.update( {}, { $push : { names : "michael" } }, false, true );

查看official docs on Updating了解更多信息,一般语法为:

db.collection.update(criteria,objNew,upsert,multi)

答案 1 :(得分:1)

您检查了this文件吗?

db.your_collection.update({your_documents} { $push : { name : "michel" }})