Using objects as _id in MongoDB
Using objects as _id
fields in MongoDB can be dangerous.
Something that has to be written with bold red text, but anyway,
it's in the official documentation:
"Unlike JavaScript objects, the fields in a BSON document are ordered."
So, you can accidentally have documents like { _id: { name: "Launchpad", surname: "McQuack" } }
and { _id: { surname: "McQuack", name: "Launchpad" } }
in the same collection.
I have encountered this issue only once in production code, and fortunately, it was many years ago. However, I still see people using objects as identifiers or hash objects without sorting the properties, hence the post.