У Mongoose поддерживает метод MongoDB `FindandModify`

Я хотел бы использовать FindandModify, чтобы аторично увеличивать поле, используя Mongoose.

Тем не менее, код ниже бросает ошибку «TypeError: Object # не имеет метода« indandAndModify »:

// 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!");
     }
});
32
задан peterjwest 3 February 2017 в 19:01
поделиться