A problem occurs: The_id
field of data 2 is in thefriends
field of data 1. At this time, I want to delete data 2, but thefriends
field The_id
field is not deleted.
Question: After deleting data 2, all_id
related to field 2 will be automatically deleted.
If it cannot be deleted automatically, does it mean that I have to re-query and then delete it? ?
I searched around on Baidu but couldn’t find the answer. Maybe I didn’t catch the keyword. . So I came here to ask. . Daniel, please help me.
Yes, unlike
relational database
, inMongoDB
you need to query and delete it yourself. Maybe in order to delete it quickly, you may also need to reversely record the relationship.MongoDB does not have cascading deletes. When an application needs to delete data, the application itself is responsible for removing any references related to the deleted data.