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

286
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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