Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Escaping '$' in pymongo
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  websockets and pymongo exception sankar2000 0 953 Oct-07-2022, 09:52 PM
Last Post: sankar2000
  PyMongo error bagou450 0 786 Aug-04-2022, 08:27 AM
Last Post: bagou450
Exclamation MongoDB cannot connect - pymongo speedev 1 2,054 Aug-21-2021, 01:35 PM
Last Post: ndc85430
  pymongo wildcard query issue MikeAW2010 2 4,210 Jul-06-2021, 09:25 AM
Last Post: swag
  Introduction to escaping characters in strings Geelong_crazy 1 2,793 Jul-18-2020, 06:58 PM
Last Post: DT2000
  CSV file escaping characters lokhtar 2 2,626 Dec-09-2019, 06:48 PM
Last Post: lokhtar
  Load JSON file data into mongodb using pymongo klllmmm 1 11,799 Jun-28-2019, 12:47 AM
Last Post: klllmmm
  Escaping whitespace and parenthesis in filenames jehoshua 2 9,628 Mar-21-2018, 09:12 AM
Last Post: jehoshua
  how to get the list of databases to a variable using pymongo? dvsrk563 1 9,290 Aug-10-2017, 08:01 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020