I am using mongoose-plugin-autoinc to autoincrement id by 1 for each item.
I want to do the exact same thing for a second field named "position" so that I can implement some drag & drop product sort UI.
How would you do ?
This is my product Model :
const productSchema = new mongoose.Schema({
name: { type: String, required: true, unique: true },
...
)}
productSchema.plugin(autoIncrement, {
model: "Product",
field: "_id",
startAt: 0,
incrementBy: 1,
});
const Product = mongoose.model("Product", productSchema);
I tried adding a second block like this but it didn't work
productSchema.plugin(autoIncrement, {
model: "Product",
field: "pos",
startAt: 0,
incrementBy: 1,
});