Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

70
Views
Autoincrement multiple field Mongoose

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,
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!