I am a newbie to mongodb. I want to write a query to print part of the column from database.
Here is the data,
{
"user-id" : "u1",
"username" : "amy",
},
{
"user-id" : "u2",
"username" : "billy",
},
{
"user-id" : "u3",
"username" : "charlie",
},
{
"user-id" : "u4",
"username" : "david",
}
It's working fine if I print the "username" with
db.user.find().forEach(
function(myDoc) {
print( "user: " + myDoc.username );
});
But I can't print the fields with a hyphen in it,
db.user.find().forEach(
function(myDoc) {
print( "user: " + myDoc.user-id );
});
Error:
Error: Line 3: Unexpected token (
I tried "user-id", "user-id", but its not work. How do I print the fields with a hyphen in it? Thanks.