重复的查询条件:__ raw__

时间:2013-06-24 01:20:54

标签: mongoengine

我制作了自定义QuerySet:

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')

这是什么?怎么决定呢?

0 个答案:

没有答案