While working on a project with Meteor and mongoDB, I encountered an issue. The problem arises when trying to retrieve the value of a field with a hyphenated name using map
. How can I work around this obstacle?
The specific field in my mongoDB collection is named:
"loopback-mode" : "no-loopback",
The query in question is:
db.collection.find({templateName:"someTemplate"},{"loopback-mode":1,_id:0}).map(function(c) {return c.loopback-mode;})[0];
It appears that referencing c.loopback-mode
is resulting in an error.
The error message received reads:
SyntaxError: Unexpected token -
I've tried variations like
c[loopback-mode], c["loopback-mode"], c."loopback-mode"
, without success. What is the correct method to resolve this issue?