Bottom Page

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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Introduction to escaping characters in strings Geelong_crazy 1 177 Jul-18-2020, 06:58 PM
Last Post: DT2000
  CSV file escaping characters lokhtar 2 414 Dec-09-2019, 06:48 PM
Last Post: lokhtar
  Load JSON file data into mongodb using pymongo klllmmm 1 5,772 Jun-28-2019, 12:47 AM
Last Post: klllmmm
  pymongo wildcard query issue MikeAW2010 1 1,540 Apr-09-2019, 06:32 PM
Last Post: reniformpuls
  Escaping whitespace and parenthesis in filenames jehoshua 2 2,920 Mar-21-2018, 09:12 AM
Last Post: jehoshua
  how to get the list of databases to a variable using pymongo? dvsrk563 1 2,187 Aug-10-2017, 08:01 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)