Escaping '$' in pymongo - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Escaping '$' in pymongo (/thread-24447.html) |
Escaping '$' in pymongo - raulp2301 - Feb-14-2020 I am searching for a specific value in my mongo cursor. If it is found then i want to extract the substring after the search value The below code works for me cursor3 = db.collection_name.aggregate( [ {'$match':{'recordId':'9d9006f6-c391-4641-a32e-59cadbdab57b'}}, { '$project': { 'recordId': { '$ifNull': ["$recordId", ""]}, 'practiceId': { '$cond': { 'if': { extract_application : 'orca'} , 'then' : {'$substr': ["sdf#asda$123", { '$indexOfBytes': [{ '$ifNull': ["$eventSource.orgName", ""]}, '#'} ] },-1]}, 'else': 'jam' ]} }} } }]) my string is sdf#asda$123 and the search criteria is #. the output is as '#asda$123' however if i change the search criteria from # to $, i get the below error: OperationFailure: '$' by itself is not a valid FieldPath |