mongojs用update命令替换文档

时间:2013-10-15 08:01:42

标签: node.js mongodb mongojs

使用mongojs,我们需要使用下面给出的代码

更新文档
db.data.update(
 {
   "title": {$regex : '.*Green Red.*', $options : 's'},
   "editor.key": {"$in": ["74014","45339"]},`enter code here`
   "types" : "Notes"
 },
{
$set: {
        "editor.key": "05335",
        "editor.value": "editor1",
        "editor.email": "editor1@gmail.com"
      }
},
false,
 true
);

但问题是它真的不是动态的

exports.updatePerson  = function(Person , onDone) {
Person.UpdatedOn = new Date();

 db.people.save(nodd, function (err) {

onDone();
});

但它创建了重复记录

1 个答案:

答案 0 :(得分:1)

试试这个:

db.data.update(
 {
   "title": {$regex : '.*Green Red.*', $options : 's'},
   "editor.key": {"$in": ["74014","45339"]},`enter code here`
   "types" : "Notes"
 },
{
$set: {
        "editor.key": "05335",
        "editor.value": "editor1",
        "editor.email": "editor1@gmail.com"
      }
},{
  insert:false,
  multi : true
}
);

insert和multi参数应该是对象的字段