1
我使用MongoDB的3.0 - 如果我有這樣的(簡版)一DOC:蒙戈查詢子文檔和打印在同一行
{
"_id": "10",
"Timestamp": ISODate("2015-09-07T09:54:45.000Z"),
"StudentData": [
{
"Name": "John"
"Town": "ZZZZZ"
"Available": true
},
{
"Name": "Mary"
"Town": "XXXXXX"
"Available": false
}
]
}
我需要打印這樣的結果:
Mon Sep 07 2015 10:54:45 GMT+0100 (GMT Daylight Time),John,true
Mon Sep 07 2015 10:54:45 GMT+0100 (GMT Daylight Time),Mary,false
我曾經嘗試這樣做:
db.students.find(
{_id:10})
.forEach(function(x){
print(
x.Timestamp
+","+
x.StudentData.Name
+","+
x.StudentData.Available
);
});
但我得到的結果早在
星期一2015年9月7日10時54分45秒GMT + 0100(GMT夏令時間),不確定的,不確定的
也許這是在正確的軌道:
var cursor =
db.students.aggregate(
{$match: {_id: "10"}},
{$unwind: '$StudentData'});
print(cursor.result);
還是我的標誌我的方式??
優秀的答案..謝謝 – gpullen