我正试图在我的数据库中进行标题搜索,但我做不到
import pymongo
myclient = pymongo.MongoClient("mongodb+srv://LOGIN:PASS@cluster0.ye4cx.mongodb.net/info?retryWrites=true&w=majority&ssl=true&ssl_cert_reqs=CERT_NONE")
mydb = myclient["info"]
mycol = mydb["comics"]
find = mycol.find({"title": {"$search": "68"}})
for f in find:
print(f)
但是我得到了这个错误
raise OperationFailure(msg % errmsg, code, response,
pymongo.errors.OperationFailure: unknown operator: $search, full error: {'operationTime': Timestamp(1601923289, 13), 'ok': 0.0, 'errmsg': 'unknown operator: $search', 'code': 2, 'codeName': 'BadValue', '$clusterTime': {'clusterTime': Timestamp(1601923289, 13), 'signature': {'hash': b'\x82\x91\xc5\xd4r\xd6\xbf\xbc\x13i\xe5\x83b\xd2\x9eUv\xb8\x89/', 'keyId': 6869109962937729027}}}
您需要使用
$text
操作符使其工作。不要忘记在标题字段上创建索引这将搜索所有索引字段并返回匹配字段。请参阅有关official documentation的更多详细信息
$search是聚合管道操作符。有关正确用法,请参见https://docs.atlas.mongodb.com/reference/atlas-search/query-syntax/#query-syntax-ref。无法在查找查询中指定它
相关问题 更多 >
编程相关推荐