Checking the integrity of the link (foreign key) in MongoDB

I am linking two MongoDB collections, for example, Aand Bby storing the B'sObjectId in A(say A.bId). How to find all instances Awhere it is bIdno longer valid (the corresponding one Bdoes not exist)?

Based on the answers and the official documentation , it’s clear that MongoDB doesn’t force links. Therefore, I need an effective way to find invalid links A'sto clear them.

Aand B- large collections, so I would like to:

  • Loading all B.id'sinto memory and execution$nin
  • Iterate through everything A'sand doB.findById(A.bId)
+1
source share
2

MongoDB - . , . .

, . , , . . , .

+1

, , A , . script A.

: " () A ?" , : " , B ". post-delete A. , .

, , , , , , MongoDB. , , .

+1

Source: https://habr.com/ru/post/1589529/


All Articles