Answer the question
In order to leave comments, you need to log in
How to assign a unique id for each purchased item?
Let's say there is a store where a user buys an item:
{
id: 25,
added_at: 1598555928476
}
Answer the question
In order to leave comments, you need to log in
var id = 0;
var obj1 = {
id: ++id
}
var obj2 = {
id: ++id
}
// . . . //
console.log(obj1) // 1
console.log(obj2) // 2
type analogue of sql auto increment for mongo?
there are plugins for mongoose like this
https://github.com/chevtek/mongoose-auto-increment
but in general how would it be better to use the built-in unique _id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question