使用pymongo进行MongoDB全文搜索时类型错误 [英] MongoDB full text search with pymongo wrong type error
本文介绍了使用pymongo进行MongoDB全文搜索时类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在pymongo中进行全文搜索时遇到错误类型错误。在文档中找不到任何可以澄清此问题的内容。
以下是查询:
query={'$search':
{
'index': 'title',
'text': {
'query': 'paper'
}
}
}
result = db.find({ '$text': query } )
我收到此错误:
OperationFailure: "$search" had the wrong type. Expected string, found object, full error: {'operationTime': Timestamp(1629910737, 1), 'ok': 0.0, 'errmsg': '"$search" had the wrong type. Expected string, found object', 'code': 14, 'codeName': 'TypeMismatch', '$clusterTime': {'clusterTime': Timestamp(1629910737, 1), 'signature': {'hash': b'
xbex067xeaxfd:#x9cx83x8bx1exacx15x8ex93xcbx06=xe0', 'keyId': 6959643758958739458}}}
它需要字符串,但我不知道它在哪里。
推荐答案
数据模型:
{
"title":"paper work"
}
首先,创建索引。
db.collection.createIndex( { title: "text" } )
第二,文本搜索。
db.collection.find( { $text: { $search: "paper" } } )
这篇关于使用pymongo进行MongoDB全文搜索时类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文