我得到一个错误的类型错误在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'rxbex067xeaxfd:#x9cx83x8bx1exacx15x8ex93xcbx06=xe0', 'keyId': 6959643758958739458}}}
它需要一个字符串,但我不知道在哪里。
数据模型:
{
"title":"paper work"
}
首先,方法createIndex .
db.collection.createIndex( { title: "text" } )
第二,文本搜索。
db.collection.find( { $text: { $search: "paper" } } )