我正在尝试从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
我该如何解决?