Solved

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

Posted on 2015-01-28
1
503 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to pass values to HTML-5 attribute dynamically? 24 51
Saving Web Page as PDF 9 47
AngularJS: ng-repeat 25 26
Scroll 5 news at a time using vticker 2 11
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

726 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