darshanmarathe
darshanmarathe

Reputation: 1

mongojs replacing document with update command

With mongojs we need to update the document with something like below given code

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": "[email protected]"
      }
},
false,
 true
);

But the problem is its really not dynamic

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

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

onDone();
});

But its creating a duplicate record

Upvotes: 0

Views: 807

Answers (1)

Ostro
Ostro

Reputation: 338

try this :

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": "[email protected]"
      }
},{
  insert:false,
  multi : true
}
);

insert and multi parameter should be fields of an object

Upvotes: 1

Related Questions