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

292
Visualizações
How to remove The "ObjectId" around the _id in the MogoDB object and log the object?

I have created an Object in MongoDB.

{
 _id : new ObjectId("62181c392c33d3fc59f55ddc"),
name: Escalade,
Brand: Cadillac

}

I want to log the object without ObjectId in the _id

{
  _id : "62181c392c33d3fc59f55ddc";
 name: Escalade,
Brand: Cadillac

}

How to do it?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When you add a value in mongodb, in a mongo db collection, it automatically makes a field name _id that is used as a primary key.

Think of it this way. This is how mongo knows the difference between an entry and an other entry

ex:

{
 _id : "62181c392c33d3fc59f55ddc";
 name: Escalade,
 Brand: Cadillac
}
{
 _id : "62181c392c33d3fc59f55ddf";
 name: Escalade,
 Brand: Cadillac
}

The first Escalade (for mongo) is different from the second Escalade

The only way to get rid of this "_id", is to declare it, when you make the entry.

For example make an entry like this:

{
 _id : "1";
 name: some_name,
 Brand: some_brand
}

The new entry will have your own _id and mongo will know that "some_name" has the _id of 1

You can search furthermore here: https://docs.mongodb.com/manual/core/document/

Specifically, when you leave this field ("_id") empty, mongo just inputs an object Id variable. So, you cannot remove it, just declare the "_id" as a string or an integer, basically anything but not an array

about 4 years ago · Juan Pablo Isaza Relatório
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