When a value is added in mongodb within a collection, it automatically creates a field called _id which serves as the primary key for that entry.
It's like a unique identifier that helps mongo distinguish between different entries.
For instance:
{
_id : "62181c392c33d3fc59f55ddc";
name: Escalade,
Brand: Cadillac
}
{
_id : "62181c392c33d3fc59f55ddf";
name: Escalade,
Brand: Cadillac
}
In this case, the first and second "Escalade" are considered distinct by mongo.
To avoid the default "_id" assigned by mongo, you can specify your own when creating an entry.
For example, create an entry like this:
{
_id : "1";
name: some_name,
Brand: some_brand
}
By providing your custom _id, mongo will associate "some_name" with the id of 1.
For further details, refer to:
https://docs.mongodb.com/manual/core/document/
If you do not provide an _id, mongo generates an ObjectId by default. It cannot be removed, but simply define the _id as a string or integer - anything except an array.