Remote error from mongot :: caused by :: "text" must be a document,

def search_by_occasion( occasion_names, age_floor, age_ceiling, output_hash):


        result = None
        user_collection = pymongo.collection.Collection(g.db, "gemift_product_db")
        result = user_collection.aggregate([{ "$search": { "index": "gemift_product_db", "text": [{ "$query": ["birthday"], "path":"occasion" }] }}])
        output_hash = copy.deepcopy(result)
        print ("The result is ", result)
        return True
    except errors.PyMongoError as e:
        print ("The error is ", e)
        return False
    except Exception as e:
        print ("The generic exception is ", e)
        return False

I get the following error when I execute the above code

Remote error from mongot :: caused by :: “text” must be a document, full error: {‘operationTime’: Timestamp(1633678006, 1), ‘ok’: 0.0, ‘errmsg’: ‘Remote error from mongot :: caused by :: “text” must be a document’, ‘code’: 8, ‘codeName’: ‘UnknownError’, ‘$clusterTime’: {‘clusterTime’: Timestamp(1633678006, 1), ‘signature’: {‘hash’: b’\xb8\xc9\x1a\x0f\x15\x05$,\x9a\x8d\x834\xf3\xd0\xc3\x9f\xa6\xf8\xe4#’, ‘keyId’: 6951462280051556353}}}

Appreciate the help

1 Like

Hi Sravana, Welcome to the MongoDB community forum! There are a lot of great folks in here.

Your query is pretty close, but you passed text as a List in the query above. Below, I’ve modified it to the correct syntax and included a github repo I threw together for Python about a year ago. Let me know if you have questions.

Basic example of Python and Atlas Search

If you go to the search tester in the Atlas UI, you can also see a basic example generated when you cliock view syntax and switch to the python language. I hope this helps. Let us know.

1 Like

Thanks Marcus. It works. Let me go through your example code. I am hitting issues after issues, but having fun learning :wink: Now I need to find out how to solve mongodb cannot pickle SSL context :slight_smile: . Running flask, python and flask_pymongo. As someone new to Atlas search (and seriously evaluating for a startup), lack of documentation and examples are slowing down. I, however, appreciate your immediate response. I will continue to use this forum for my questions.



My example is not a great one, but it is a useful python resource. I probably need to update it sometime soon. I will keep you posted. Good luck at your startup!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.