Why .(dot) is a bad idea for key name in mongodb

I find that I like mongodb. In my student years, I had trouble understanding why RDBMS are structured the way they are structured. And why you can’t just save whatever the data we want to save? In RDBMS we always had to design everything before hand. While designing databases is good, sometimes it’s difficult to move forward because you are tied to specific design. However, mongodb is not like that. You can always just save the document the way it is. Actually, what happens in reality it really accelerates development, because db is just on less worry now, when using mongodb. I’ve decided that I will be sharing some interesting things that I find about mongodb.

The first thing that I’d like to share about mongodb is that don’t use .(dot) as your key name!

The reason is that .(dot) will create subdocuments!

So, imagine that you want to save this id: apac.id.123

What happens when you pass that id, mongodb will save it apac being it’s root, id it’s child and 123 child of id!

Same goes for the $ sign.

https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Field-Names

Leave a Reply

Your email address will not be published. Required fields are marked *