Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda