各位,
我试图在 find 方法上使用 fields 参数,我得到了以下错误代码:
TypeError: __init__() got multiple values for keyword argument 'fields'
代码:
mongo.db.products.find({ '$text': { '$search': string } }, { 'score': { '$meta': 'textScore' } }, fields=('name', 'foo', 'bar',))
在没有全文搜索的情况下,fields 参数工作正常。
最佳答案
对于 pymongo,'textScore' 的“投影部分”需要以完整形式包含在“字段”规范中:
mongo.db.products.find(
{ '$text': { '$search': string } },
fields=({ 'name': 1, 'foo': 1, 'bar': 1, 'score': { '$meta': 'textScore' } )
)
关于python - PyMongo 在全文搜索中选择字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25373429/