Solved

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

Posted on 2015-01-28
1
389 Views
Last Modified: 2016-02-10
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?
0
Comment
Question by:dlethe
1 Comment
 
LVL 47

Accepted Solution

by:
dlethe earned 0 total points
ID: 40576198
Solved it ... you need to use dot notation

so a field name such as e-1 would be represented by ['e-1']
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now