use*_*659 14 javascript find mongodb bson
我的mongoDB集合看起来像这样:
{
"_id" : ObjectId("5070310e0f3350482b00011d"),
"emails" : [
{
"_id" : ObjectId("5070310e0f3350482b000120"),
"_type" : "Email",
"name" : "work",
"email" : "peter.loescher@siemens.com",
"current" : true
}
]
}
Run Code Online (Sandbox Code Playgroud)
这是.js我用来打印内容的代码:
c = db.contacts.findOne( { "emails.email" : { $ne : null } }, { "emails" : 1 } )
print(c._id.toString() + " " + c.emails[0]);
Run Code Online (Sandbox Code Playgroud)
当我尝试运行这个javascript文件时,它只是显示id而不是电子邮件数组.
output:
5070310e0f3350482b00011d [object bson_object]
Run Code Online (Sandbox Code Playgroud)
但是当我尝试c.emails[0].email的是给出正确的结果.即peter.loescher@siemens.com
我只需要显示整个电子邮件嵌入对象.
i.e.
"emails" : [
{
"_id" : ObjectId("5070310e0f3350482b000120"),
"_type" : "Email",
"name" : "work",
"email" : "peter.loescher@siemens.com",
"current" : true
}
]
Run Code Online (Sandbox Code Playgroud)
我哪里错了?任何帮助,将不胜感激.
Ale*_*rov 32
您需要printjson输出格式良好的JSON:
printjson(c.emails[0]);
Run Code Online (Sandbox Code Playgroud)
这是文档.
| 归档时间: |
|
| 查看次数: |
10538 次 |
| 最近记录: |