NodeJS and MongoDB FindAndModify() need remove or update

前端 未结 4 1407
抹茶落季
抹茶落季 2020-12-03 11:32

im trying to do a findAndModifiy in mongodb with nodejS, This is my code:

var nextBill = function (db, success, log) {
    var collection = db.collection(\'         


        
4条回答
  •  伪装坚强ぢ
    2020-12-03 12:00

    Hi I have followed this and it worked perfectly.
    
    db.collection('test').findAndModify(
      {hello: 'world'}, // query
      [['_id','asc']],  // sort order
      {$set: {hi: 'there'}}, // replacement, replaces only the field "hi"
      {}, // options
      function(err, object) {
          if (err){
              console.warn(err.message);  // returns error if no matching object found
          }else{
              console.dir(object);
          }
      });
    });
    

提交回复
热议问题