相关疑难解决方法(0)

Mongoose是否支持Mongodb`searchAndModify`方法?

我想使用findAndModify使用Mongoose以原子方式递增字段.

但是,下面的代码会引发错误"TypeError:Object#have method'seadAndModify'":

// defining schema for the "counters" table
var tableSchema = new Schema({
    _id: String,
    next: Number        
});

// creating table object for the counters table
var counters_table = mongoose.model('counters', tableSchema);
var tableObj = new counters_table();    

// increment the "next" field on the table object
var query = {_id: 'messagetransaction'};
var update = {'$inc': {next: 1}};
var ret = tableObj.findAndModify(query, [], update, true, true, function(err) {
     if (err) { 
         throw err;
     }
     else { 
         console.log("updated!");
     }
});
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb

32
推荐指数
5
解决办法
4万
查看次数

标签 统计

mongodb ×1

mongoose ×1