简体   繁体   English

Django中Mongodb中的级联更改

[英]Cascade changes in Mongodb in Django

Is there a way to change a element of collection in Mongoose and be cascade changed in other collection that points this element, similar to using MySQLs foreign keys? 有没有一种方法可以更改Mongoose中的collection元素,并在指向该元素的其他collection中进行级联更改,类似于使用MySQL的外键?

For example, in MySQL I'd assign a foreign key and set it to cascade on change or delete. 例如,在MySQL中,我将分配一个外键并将其设置为在更改或删除时级联。 Thus, if I were to delete or change name of a activity_Type, all applications and associated activity_Types would be removed or affected as well. 因此,如果我要删除或更改activity_Type的名称,那么所有应用程序和关联的activity_Types也将被删除或受影响。

class ValuesHelper(object):


    NAME = 'activityType'

    def __init__(self, neo_on=False):
        self.client = MongoClient(settings.DATABASES['mongo']['HOST'],settings.DATABASES['mongo']['PORT'])
        self.db = self.client[settings.DATABASES['mongo']['NAME']]

Unfortunately, there is no support for cascade changes at the moment. 不幸的是,目前不支持级联更改。 (Take a look at this jira ticket ) (看看这张吉拉票

So you need to implement that behavior in your application. 因此,您需要在应用程序中实现该行为。 For example, if you were using Mongoose, you can do it using its remove Middleware. 例如,如果您使用的是Mongoose,则可以使用其remove中间件来实现。 Take a look at JohnnyHK's answer from another SO question for an example. 来看另一个例子中JohnnyHK的回答

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM