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.
曾经蜡笔没有小新2017-07-03 11:43:12
Yes, unlike relational database
, in MongoDB
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 has no cascading deletes. When your application deletes data, it is also responsible for removing any referenced objects itself and any references to the deleted document.
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.