python - MongoDB Atlas Search:预期的“管道”是 BSON 文档(或等效文档),但得到的是 original.A
问题描述
我正在尝试运行以下 python 代码,但标题中出现错误。感谢帮助
这是代码
def search_by_xyz(self, occasion_names, age_floor, age_ceiling, output_hash):
#occasion names should be a list
try:
search_string = '{ "$search": { "index": "prod_coll", "$text": [{ "$query": ["birthday"], "path":"occasion" }] } } '
#search_string = bson.BSON.encode(search_string)
print (search_string)
result = None
result = g.db.prod_coll.aggregate([search_string])
output_hash = copy.deepcopy(result)
print ("The result is ", result)
return True
except errors.PyMongoError as e:
current_app.logger.error(e)
print ("The error is ", e)
return False
except Exception as e:
current_app.logger.error(e)
print ("The generic exception is ", e)
return False
错误:
Expected 'pipeline' to be BSON docs (or equivalent), but got primitive.A instead.
Doc = [{aggregate prod_coll} {pipeline [{ "$search": { "index": "prod_codd", "$text": [{ "$query": ["birthday"], "path":"occasion" }] } } ]} {cursor []} {lsid [{id {4 [61 128 170 27 187 104 78 150 167 30 151 104 104 195 199 76]}}]} {$clusterTime [{clusterTime {1633671836 1}} {signature [{hash {0 [142 154 244 184 197 78 72 186 85 73 7 33 135 63 176 180 173 233 113 219]}} {keyId 6951462280051556353}]}]} {$db sample_airbnb} {$readPreference [{mode primary}]}], full error: {'ok': 0, 'errmsg': 'Expected \'pipeline\' to be BSON docs (or equivalent), but got primitive.A instead. Doc = [{aggregate prod_coll} {pipeline [{ "$search": { "index": "prod_coll", "$text": [{ "$query": ["birthday"], "path":"occasion" }] } } ]} {cursor []} {lsid [{id {4 [61 128 170 27 187 104 78 150 167 30 151 104 104 195 199 76]}}]} {$clusterTime [{clusterTime {1633671836 1}} {signature [{hash {0 [142 154 244 184 197 78 72 186 85 73 7 33 135 63 176 180 173 233 113 219]}} {keyId 6951462280051556353}]}]} {$db sample_airbnb} {$readPreference [{mode primary}]}]', 'code': 8000, 'codeName': 'AtlasError'}
解决方案
推荐阅读
- php - API平台如何快速遏制复数失败?
- c# - 如何正确地将特定时区的午夜转换为UTC时间?
- java - 我的位图编码可用于其他平台吗?
- android - android studio 构建时间过长
- mysql - MySQL - 按最近日期加入两个表
- python - Tensorflow:RaggedTensor.from_tensor 将所有数组中的值展平到一个数组中,而不是保留原始数组数量
- python - 如何根据列值合并数据框中的行?
- ios - 点击时TableView单元格消失/ reloadData不改变单元格?
- php - 一个 laravel 应用程序上的多个网站
- reactjs - React Context API + withRouter - 我们可以一起使用它们吗?