我制作了自定义查询集:
class CustomQuerySet(QuerySet): def get_campaign(self, name=None): query = {'campaigns': { '$elemMatch': { '_syskey': name or 'default'}}} return self.filter(__raw__=query)[0] class Client(Document): ... meta = { 'collection': 'my_collection', 'allow_inheritance': False, 'indexes': ['client_id', ], 'queryset_class': CustomQuerySet }
运行到控制台:
client = Client.objects(client_id=2) client.get_campaign('default') client.get_campaign('default') # here exception is born InvalidQueryError: Duplicate query conditions: __raw__
如果我再次重复 1 和 2 命令,则不会出现异常:
client = Client.objects(client_id=2) client.get_campaign('default')
但在重复 3 行异常之后:
client.get_campaign('default')
它是什么?怎么决定?