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

后端 未结 6 678
暗喜
暗喜 2020-11-28 15:31

Let\'s say I have a collection of documents such as:

{ \"_id\" : 0 , \"owner\":0 \"name\":\"Doc1\"},{ \"_id\" : 1 , \"owner\":1, \"name\":\"Doc1\"}, etc
         


        
6条回答
  •  臣服心动
    2020-11-28 16:08

    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.

提交回复
热议问题