有一个像这样的集合
MongoDB Enterprise datap:SECONDARY> db.employee.find({"id":"12345"},{rltns:1});
{
"_id" : ObjectId("XXXXX"),
"rltns" : {
"MO" : {
"field1" : "hi",
"field2" : "hello",
"field3" : "aloha",
"field4" : "namaste",
"field5" : "oi",
},
"FA" : {
"field1" : "check01",
"field2" : "check02",
}
}
}
}
不同关系的数量可以是0,1或多个
我们只需要打印id和field1 / field2
的数据如何获得以下格式的文件?
12345 | MO | hi | hello
12345 | FA | check01 | check02
答案 0 :(得分:0)
您可以根据需要准备查询:
let projection : {};
for(let i = 0; i < numberOfValue; i++) {
Object.assing(projection, {
["fields"+i]: 1
});
}
db.employee.find({_id: "12345"}, projection, function(err, result) {
});