A problem occurs: The _id
field of data 2 is in the friends
field of data 1. At this time, I want to delete data 2, but the friends
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.