How to enforce foreign keys in NoSql databases (MongoDB)?

MongoDB doesn’t have foreign keys (as you have presumably noticed). Fundamentally the answer is therefore, “Don’t let users tamper with the requests. Only let the application insert data that follows your referential integrity rules.”

MongoDB is great in lots of ways… but if you find that you need foreign keys, then it’s probably not the correct solution to your problem.

Leave a Comment