Link to home
Start Free TrialLog in
Avatar of David
DavidFlag for United States of America

asked on

How to escape a field name in mongodb that has dashes in it

I have a mongodb document that is autogenerated that uses dashes in field names.  How do I construct a query or assignment that uses them ?   It doesn't like embedded dashes and I can't figure out how to escape the field names so I can use them as variables in expressions.

 
"Doc" : [
  {
    "field-1" : "alpha",
    "stuff": {
       "more-stuff" :  1,
       "even-more-stuff" : 2,
       "embedded-array" : [ 
          {
            "e-1": 100, 
           "e-2":101
          }
       ]
      } 
  },
  {
     "field-1" : "beta",
     "stuff": {
       "more-stuff" :  3,
       "even-more-stuff" : 4,
       "the-cookie":55
        } 
  }
]

Open in new window


How would I assign x to the field name associated with "The cookie" and then, so It is a better learning experience, create a cursor on "embedded-array" so a jsonprint(EmbeddedArray")  reports the e-1 and e-2 fields and values?
ASKER CERTIFIED SOLUTION
Avatar of David
David
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial