🔥 Burn Fat Fast. Discover How! 💪

MongoDB foreign key There is no real SQL foreign key in Mongo | Andrey Ivanov | Python

MongoDB foreign key

There is no real SQL foreign key in MongoDB. However, we can create it manually. That is, we will point to the ID of some documents, but these IDs will not be checked by the database. But, do we need foreign keys in MongoDB? The fact is that BSON(an addition to JSON) can accept almost any data. For example, if you have an online store with products, and each product has some tags(Italian food, Chinese food, etc.), then these tags can be stored in an array inside our document. This will boost the performance of the queries, since MongoDB will not search for tags in some other collections, but will simply give them in the array of the found document. This approach is very different from standard SQL, where to normalize tables, we need to move all duplicate values to other tables, and then create a foreign key.