Tha*_*150 1 javascript mongodb node.js
我有一个像这样的示例 mongo 文档:
> db.chat.find().pretty()
{
"_id": ObjectId("555f1c0c7f4b820758b439b0"),
"user": "Guest1",
"friend": [{
"userfriend": "Guest2",
"noidung": [{
"method": "send",
"date": "2015-05-22T19:11:34+07:00",
"content": "allloooo"
}, {
"method": "receive",
"date": "2015-05-23T09:08:14+07:00",
"content": "yes man"
}]
}, {
"userfriend": "Guest3",
"noidung": [{
"method": "send",
"date": "2015-05-23T15:42:34+07:00",
"content": "foo 15:42"
}, {
"method": "receive",
"date": "2015-05-23T15:42:45+07:00",
"content": "bar 15:43"
}]
}]
}
Run Code Online (Sandbox Code Playgroud)
在我的 server.js 中,我使用以下代码来打印所有数据:
var chathistory = db.collection('chat');
chathistory.find().toArray(function (err, docs) {
console.log(docs)
});
Run Code Online (Sandbox Code Playgroud)
我在终端中收到此日志:
[ { _id: 555f1c0c7f4b820758b439b0,
user: 'Guest1',
friend: [ [Object], [Object] ] } ]
Run Code Online (Sandbox Code Playgroud)
“朋友”字段不会打印全部,而是唯一的[Object],那么我怎样才能获得完整的数据。
要打印所有数据,请使用以下JSON.stringify()方法
db.collection('chat').find().toArray(function(err, docs) {
console.log(JSON.stringify(docs));
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7259 次 |
| 最近记录: |