我的mongoDB集合看起来像这样:
{
"_id" : ObjectId("5070310e0f3350482b00011d"),
"emails" : [
{
"_id" : ObjectId("5070310e0f3350482b000120"),
"_type" : "Email",
"name" : "work",
"email" : "[email protected]",
"current" : true
}
]
}
这是我用来打印内容的.js
代码:
c = db.contacts.findOne( { "emails.email" : { $ne : null } }, { "emails" : 1 } )
print(c._id.toString() + " " + c.emails[0]);
当我尝试运行这个javascript文件时,它只是显示id而不是电子邮件数组。
output:
5070310e0f3350482b00011d [object bson_object]
但是,当我尝试c.emails[0].email
是给出正确的结果。即[email protected]
我只需要显示整个电子邮件嵌入对象。
i.e.
"emails" : [
{
"_id" : ObjectId("5070310e0f3350482b000120"),
"_type" : "Email",
"name" : "work",
"email" : "[email protected]",
"current" : true
}
]
我哪里错了?任何帮助,将不胜感激。