NodeJS and MongoDB FindAndModify() need remove or update

前端 未结 4 1410
抹茶落季
抹茶落季 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

    http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#findAndModify

    This above document specifies that the second parameter is the sort order for choosing which document to use if multiple ones match the query. Only giving two parameters will result in the "need remove or update" error message.

    collection('MyCollection').findAndModify(
        { _id: "auto" },
        [],
        { $inc: { "bill": 1 } },
        { upsert: true, new: true },
        function(err,doc) {
           // work here
        }
    );
    

提交回复
热议问题