Mongo를 처음 접했을 때 나는 꽤 이해하지 못합니다.
왜 test2 컬렉션의 다음 항목에 대해 첫 번째 쿼리는 작동하지만 두 번째 쿼리는 작동하지 않습니다.
그리고 왜 쿼리가 나에게 사용자의 전체 내용이 아닌 오직 사용자의 _id만을 제공하는 반면, 사용에 대한 모든 정보를 사용자에게 제공하는 이유는 무엇입니까?MongoDB 쿼리 질문 : 한 필드의 선택 영역에 값이 있고 다른 필드가 설정되어 있지 않은지 어떻게 표현해야합니까?
조회 :
db.test2.find({"invitations.acceptedDate": {$exists: false}}, {"invitations.code":"codeAA"})
db.test2.find({"invitations.code":"codeAA"}, {"invitations.acceptedDate": {$exists: false}})
가 몽고에서 쿼리를 표현의도 올바른 방법인가? 내가 쓰기 위해 노력하고있어 쿼리는 다음과 같습니다
이
"나에게 코드 초대장 (AN acceptedDate를 포함하지 않는 초대) 주장하지 않은 'codeAA'를 사용하여 초대장을 보낸 사용자의 목록을 제공하십시오"데이터 :
[{
"username": "userA",
"password": "secretA",
"invitations": [{
"code": "codeAA",
"emailSentTo": "[email protected]",
},{
"code": "codeAB",
"emailSentTo": "[email protected]",
"acceptedDate": "20110424"
}]},
{
"username": "userB",
"password": "secretB",
"invitations": [{
"code": "codeBA",
"emailSentTo": "[email protected]",
},{
"code": "codeBB",
"emailSentTo": "[email protected]",
}]},
{
"username": "userC",
"password": "secretC",
"invitations": [{
"code": "codeCA",
"emailSentTo": "[email protected]",
},{
"code": "codeAA",
"emailSentTo": "[email protected]",
"acceptedDate": "20110424"
}]},
{
"username": "userD",
"password": "secretD",
"invitations": [{
"code": "codeDA",
"emailSentTo": "[email protected]",
},{
"code": "codeDB",
"emailSentTo": "[email protected]",
}]
}]
건배
닉
아,이 결과가 왜 나는지 설명해 주셔서 감사합니다. :-) 그러나, 나는 하나의 쿼리 객체가 실제로 정확히 일치한다는 것을 알지 못한다. 코드가 codeAA이고 acceptedDate가없는 초대장이 없더라도 "userC"와 일치 할 것이다. – niklassaers
@niklassaers 답변을 업데이트했습니다. – rocky3000
대단히 감사합니다 .-) – niklassaers