DWQA QuestionsCategory: DatabaseMongodb reference cannot delete reference while deleting data
ci0n asked 4 weeks ago

Problem: data 2_idField in data 1friendsField, at this time I want to delete data 2, butfriendsField_idThe field was not deleted.
Question: after deleting data 2, all the_idAre automatically deleted.
If it can’t be deleted automatically, it means that I have to query again and delete it??
Baidu a circle, did not find the answer, should be I did not catch the keyword.. So I came here to ask.. Daniel, help me.

1 Answers
chekun answered 4 weeks ago

Yes, andRelational databaseDifferent,MongoDBYou need to query and delete by yourself. Maybe in order to delete quickly, you may also need to record the relationship in reverse.

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 has no cascading deletions. When the application needs to delete data, the application itself is responsible for removing any references related to the deleted data.

ci0n replied 4 weeks ago

Thank you very much.