하위 문서 특성 값을 기반으로하는 Mongo 쿼리에 대한 도움이 필요하지만 해당 하위 문서 특성이 결과에 표시되지 않도록해야합니다.MongoDB 하위 문서 프로젝션
{
"username" : "abc",
"emails" : [
{
"address" : "[email protected]",
"default" : true
},
{
"address" : "[email protected]",
"default" : false
}
]
},
{
"username" : "xyz",
"emails" : [
{
"address" : "[email protected]",
"default" : false
},
{
"address" : "[email protected]",
"default" : true
}
]
}
내 목표는 다음과 같은 출력을 얻을 수 있습니다 : 여기
내 사용자 객체 ("emails.default"로 : 사실하지만 결과에 나타나는 "emails.default"속성없이) :
collection.find({"emails.default":true}, {"username":1,"emails.$":1})
내가 AP에 올바른 이메일 하위 문서를 얻을 다음 $ 위치 연산자를 사용
{
"username" : "abc",
"emails" : [
{
"address" : "[email protected]",
}
]
},
{
"username" : "xyz",
"emails" : [
{
"address" : "[email protected]",
}
]
}
배,하지만 난 여전히 "emails.default"를 얻을 다시 속성 :
{
"username" : "abc",
"emails" : [
{
"address" : "[email protected]",
"default" : true
}
]
},
{
"username" : "xyz",
"emails" : [
{
"address" : "[email protected]",
"default" : true
}
]
}
을 어떤 이유로, 나는이 문장을 사용할 때 : 쿼리 것처럼 (나는 다음과 같은 결과를 얻을
collection.find({"emails.default":true}, {"username":1,"emails.address":1})
을 진술의 일부가 무시되었습니다)
{
"username" : "abc",
"emails" : [
{
"address" : "[email protected]",
},
{
"address" : "[email protected]",
}
]
},
{
"username" : "xyz",
"emails" : [
{
"address" : "[email protected]",
},
{
"address" : "[email protected]",
}
]
}
도움을 주신 데 대해 감사드립니다.