我有一个mongoose
我的模型node.js
应用程序,代表发票。我已经弄清楚了大部分内容,但我确实需要确保我的发票被编号/递增,以便能够为我的客户提供正确的参考。
使用 SQL 数据库,我会创建一个AUTO-INCREMENT
列保存这个值,但这显然不是内置在 MongoDB 中的。那么我将如何实现这一目标mongoose
?
这是我的模型现在的样子:
var InvoiceSchema = new Schema({
reference: {type: Number, default: 0}, // The property I want to auto-incr.
dates: {
created: {type: Date, default: Date.now},
expire: {type: Date, default: expiryDate()}
},
amount: {type: Number, default: 0}
// And so on
});
Controller.findByIdAndUpdate(ID_HERE, {$inc: {next:1}}, function (err, data) {
});
// 接下来是字段,类型:Number
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)