如何解决mongoengine文本搜索错误“所有$ meta排序键都必须具有$ meta投影”

时间:2019-04-19 11:03:32

标签: python mongoengine

我正在尝试从MongoDB数据库查询汉字。我已经这样定义了模型的模式:

class Character(db.Document):
    etymology = db.EmbeddedDocumentField(Etymology)
    character = db.StringField(max_length=1)
    definition = db.StringField()
    radical = db.StringField(max_length=1)
    pinyin = db.StringField(max_length=5)
    decomposition = db.StringField()
    meta = {'indexes': [
        {'fields': ['$character', "$definition", "$radical", "$pinyin", "$decomposition"],
         'default_language': 'english',
         'weights': {'character': 2, 'definition': 2, 'radical': 2, 'pinyin': 2, 'decomposition': 2}
         }
    ]}

我的数据库已经包含字符数据。当我尝试使用Character.objects.search_text方法时,出现以下错误:

pymongo.errors.OperationFailure: must have $meta projection for all $meta sort keys

我该如何解决?

0 个答案:

没有答案