作为Mongodb中的一只新蜜蜂,我正在使用一本书作为参考。在本书中,我们讨论了一种访问集合中文档元素的方式。我正在尝试使用打印功能而不是组合功能在书里。
//code from the book
>db.blog.find()
{
"title" : "My Blog Post",
"content" : "Here's my blog post.",
"date" : "Sat Dec 12 2009 11:23:21 GMT-0500 (EST)"
}
var collections = ["posts", "comments", "authors"];
for (i in collections) {
doStuff(db.blog[collections[i]]);//Instead of doStuff i am using print
}
//but when i write the below code i am not getting what is expect
var collections = ["posts", "comments", "authors"];
for (i in collections) {
print(db.blog[collections[i]]);//Instead of doStuff i am using print
}
我期望的输出是什么
"My Blog Post"
"Here's my blog post."
"Sat Dec 12 2009 11:23:21 GMT-0500 (EST)"
我得到的是什么
foodbar.blog.name
foodbar.blog.content
foodbar.blog.date