Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda