我有以下结构的文件:
{
"_id" : ObjectId("50b8f881065f90c025000014"),
"education" : {
"schoolCountry" : 4,
"schoolTown" : -1,
"uniCountry" : 4,
"uniTown" : -1
},
"info" : {
"ava" : "auto.jpg",
"birthday" : ISODate("1942-04-01T21:00:00Z"),
"email" : "mail@gmail.com",
"name" : "name",
"sex" : 1,
"surname" : "surname"
}
}
我试图只输出姓氏和名字
我唯一能做到的是:
db.COLL.find({ }, {
"_id" : 0,
"education" : 0,
"info" : 1
})
我只显示子文档中我需要的元素的想法失败了:
db.COLL.find({ }, {
"_id" : 0,
"education" : 0,
"info.surname" : 1,
"info.name" : 1,
})
但隐藏 (info.email : 0) 有效。是否可以在不隐藏所有不需要的字段的情况下实现我的目标?