Solved

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

Posted on 2015-01-28
1
476 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
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…

839 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