正在使用mongodb的mongoengine开展django项目。我想在我的模型上创建一个文本索引,这就是我所拥有的
models.py
from mongoengine import *
class Questions(Document):
question_title = StringField(max_length=100)
question_text = StringField(max_length=500, required=True)
authors = ReferenceField(Users, required=True, reverse_delete_rule=CASCADE)
creation_date = DateTimeField()
votes = IntField(default=0)
#.. more fields definitions
meta = {
'indexes' : [
{
'fields' : ['$question_title', '$question_text'],
'default_language' : 'english',
'weight' : {
'$question_title': 10,
'$question_text' : 5
}
}
]
}
然后django提出了这个错误。我该怎么做才能在我的文档中创建文本索引。非常感谢任何帮助
答案 0 :(得分:1)
在索引定义(examples here)中,有一些错误:weights
而不是weight
,而不是从权重键中移除$
:
meta = {
'indexes' : [
{
'fields' : ['$question_title', '$question_text'],
'default_language' : 'english',
'weights' : {
'question_title': 10,
'question_text' : 5
}
}
]
}