Поиск по атласу MongoDB: ожидал, что «конвейер» будет документами BSON (или эквивалентом), но стал примитивным.А вместо этого

#python #mongodb

Вопрос:

Я пытаюсь запустить следующий код 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'}