
前面操作看菜鸟教程
function getNextSequenceValue(sequenceName){ var sequenceDocument = Counter.findOneAndUpdate(
sequenceName,
{$inc:{sequence_value:1}},
).exec(function(err,data){
return data.sequence_value;
});
}
但是findAndModify()方法要换成这个 findOneAndUpdate()
var mongoose = require('mongoose') var CounterSchema = new mongoose.Schema({
id:String,
sequence_value:Number
}) module.exports = mongoose.model('Counter',CounterSchema)