首页 > 解决方案 > 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'}

标签: pythonmongodb

解决方案


推荐阅读