Python Forum

Full Version: Escaping '$' in pymongo
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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