删除级联时的 MongoDB DBRef
MongoDB 有没有办法让外键具有“ON DELETE CASCADE”功能?
我知道您可以使用 DBRef 作为一种外键,但是当删除引用指向的集合中的项目时,引用将返回 null。但我希望引用所属的项目被删除。我该怎么做?
或者我每次删除东西时都需要检查对其的引用吗?
Is there a way in MongoDB to have a foreign key with a 'ON DELETE CASCADE' functionality?
I know you can use DBRef as a sort of foreign key but when the item in a collection where the reference points to is removed, the reference returns null. But i want that the item where the reference belongs to gets removed. How do i do this?
Or do i need every time i remove things check references to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个功能现在不存在了。如果你想要的话。将其添加到 MongoDB Bugtracker
http://jira.mongodb.org
This feature doesn't exist now. If you want it. Add it on MongoDB Bugtracker
http://jira.mongodb.org
没有内置的DELETE CASCADE,但您可以编写自己的登录名。这是我的
详细信息:如果类别将被删除,我必须删除库存商品。因此,我在类别删除上使用
post middleware
,在该中间件中,我找到具有该类别的库存项目并将其也删除。There is no builtin DELETE CASCADE but you can write your own login. Here is mine
Details: I have to remove stock item if category will delete. So I use
post middleware
on Category delete and in that middleware i find the Stock Item which have that category and remove that too.