_id field generated?

If a document is inserted without a provided _id value, then that field and value will be automatically generated for the inserted document before insertion.

This is true.

MongoDB ensures that each inserted document has a unique _id value.

There is maybe here an issue.
So _id is the field.
Field and value will be generated?
_id is the field, and the random _id after the : is the value.
But the field is never generated, it will be always _id, no way to change that.

Welcome to the MongoDB Community @Raphael_Attia !

If the required primary key field _id does not exist in a new document, it will automatically be added with a new pseudorandom ObjectID value.

The primary key field can only be named _id.

I think you may be focused on the language affinity of what is generated, but describing this behaviour as generating the field name and value pair of _id: ObjectID(...) seems reasonable to me.

An alternative take might be that primary key field name is generated with a constant value of _id.


1 Like

I really feel like a semantic issue here, and I failed for it :sweat_smile:
No matters.
Learning every day…
I think we can close this topic.