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

227
Views
MongoDB Mongoose - saving document with 'id' deletes id from it

I need to save document to my db. Document has different fields and one of them "id".

looks like this

"is_trial_product": 0,
"is_shippable": 1,
"tax_code": null,
"is_licensed": 0,
"id": 1,
"name": "Product 1",
"description": "bla bla bla",
"price": "44.9500", 

problem is when I use method Product.insertMany(...) and passing in array with my products it gets saved but deletes "id" from every document.

I'm getting results like this

"is_trial_product": 0,
"is_shippable": 1,
"tax_code": null,
"is_licensed": 0,
"name": "Product 1",
"description": "bla bla bla",
"price": "44.9500", 

I'm using this schema. Strict false and schema is empty because Product could have unpredictable fields so I don't want to specify them for now.

const TestProductSchema = new Schema({}, { strict: false, timestamps: true }); 

I tried options like

{ id: false }
{ _id: false } 

but it didn't help.

Maybe somebody know why is it happening and if there is a way to avoid it?

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!