Mongodb allows multiple keys with the same name

The underlying BSON storage format in MongoDB uses an ordered object representation rather than a dictionary, so technically duplicate fields are allowed (but not commonly used).

This is noted in the documentation on field names:

BSON documents may have more than one field with the same name. Most MongoDB interfaces, however, represent MongoDB with a structure (e.g. a hash table) that does not support duplicate field names. If you need to manipulate documents that have more than one field with the same name, see the driver documentation for your driver.

I would consider creation of duplicate fields when creating/editing a document via an Admin UI an unexpected outcome. The typical mental model is that MongoDB documents are JSON-like with additional field types.

Unfortunately Robo3T is not actively maintained and embeds a specific version of the mongo shell rather than using the driver API. It has a growing backlog of bugs and compatibility issues that are not being triaged.

I strongly recommend using an actively developed MongoDB admin UI such as MongoDB Compass.

For more comparison on BSON vs JSON you might be interested in: Why does MongoDB check for order of keys when matching embedded documents? (Software Engineering StackExchange).

Regards,
Stennie

4 Likes