개체에 중첩 배열이있는 컬렉션이 mongodb에 있다고 가정 해 보겠습니다. 배열의 특정 요소 값에 따라 정렬하고 싶습니다. 이것이 가능한가?Mongo에서 중첩 배열 내의 요소로 정렬 할 수 있습니까?
예를 들어 (내가 방금 만든 예제), 사용자가 제출 한 동영상 유형 (액션, 코미디, 로맨스) 및 예제가있는 경우 지정된 사용자가 제출 한 모든 개체를 찾을 수 있습니까? 영화 날짜?
예를 들어, 'Aaron'이 예제를 제출 한 'Aaron'예제의 연도별로 정렬 된 모든 유형을 찾고 싶습니다.
거의 비슷한 종류의 절이 필요합니다.
> db.movies.find(). pretty();
{
"_id" : ObjectId("4f2f07c1ec2cb81a269362c6"),
"type" : "action",
"examples" : [
{
"title" : "Gladiator",
"year" : 2000,
"submitter" : "Aaron"
},
{
"title" : "Mission Impossiple",
"year" : 1996,
"submitter" : "Bill"
},
{
"title" : "The Terminator",
"year" : 1984,
"submitter" : "Jane"
}
]
}
{
"_id" : ObjectId("4f2f07edaee5d897ea09f511"),
"type" : "comedy",
"examples" : [
{
"title" : "The Hangover",
"year" : 2009,
"submitter" : "Aaron"
},
{
"title" : "Dogma",
"year" : 1999,
"submitter" : "Bill"
},
{
"tile" : "Airplane",
"year" : 1980,
"submitter" : "Jane"
}
]
}
> db.movies.find ({ 'examples.submitter': '아론'}) 종류.. ({ 'examples.year': 1}) 꽤(); 문서가 (예상대로) 컬렉션 년으로 분류 반환
{
"_id" : ObjectId("4f2f07edaee5d897ea09f511"),
"type" : "comedy",
"examples" : [
{
"title" : "The Hangover",
"year" : 2009,
"submitter" : "Aaron"
},
{
"title" : "Dogma",
"year" : 1999,
"submitter" : "Bill"
},
{
"tile" : "Airplane",
"year" : 1980,
"submitter" : "Jane"
}
]
}
{
"_id" : ObjectId("4f2f07c1ec2cb81a269362c6"),
"type" : "action",
"examples" : [
{
"title" : "Gladiator",
"year" : 2000,
"submitter" : "Aaron"
},
{
"title" : "Mission Impossiple",
"year" : 1996,
"submitter" : "Bill"
},
{
"title" : "The Terminator",
"year" : 1984,
"submitter" : "Jane"
}
]
}
주 - 특정 사용자가 제출 단지 그 기준으로 정렬 할 수있는 방법? 내가 nodejs를 위해 노드 - 원주민 mongo 드라이버를 사용하고있는 약간의 세부 사항을 위해.
나는 그것을 할 수있을 것이라고는 생각하지 않았지만 그것이 가치가 있다고 생각했습니다. 당신이 언급 한 Aggregation Framework이 준비되었거나 안정적 일 때처럼 나를 데려다 줄 것 같아서 기쁩니다. 감사! – Zugwalt