I have a mongoose
model in my node.js
application, representing invoices. I have figured most of it out already, but I really need to ensure that my invoices are numerated/incremented to be able to provide a proper reference to my customer.
Using an SQL database, I would have created an AUTO-INCREMENT
column holding this value, but this obviosly isn't built into MongoDB. So how would I accomplish this with mongoose
?
Here's how my model looks right now:
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
});