0
여러 필드를 기반으로 내 레코드를 정렬하려고합니다. 그러나 레코드는 첫 번째 정렬 기준에 의해서만 정렬됩니다. 별도로 정렬 속성을 사용하면 잘 작동합니다.봄용 문구의 타임 스탬프 필드에서 날짜 만 지정하기
예상 결과는 먼저 생성 된 날짜별로 내림차순으로 정렬해야하며 사용자별로 정렬해야합니다. 내림차순으로 계산합니다.
다음은 내 레코드 목록입니다. 예상되는 결과는 레코드 3 레코드 2와 레코드 1의 순서 여야합니다. 먼저 createdDate로 정렬 한 다음 사용자 수로 정렬해야합니다.
// record 1
{
"_id": "a46asgasyas"
"content": "sample data set 1",
"userscount": 0,
"createdDate": ISODate("2016-12-11T13:45:53.991Z")
},
// record 2
{
"_id": "a46asgasyas"
"content": "sample data set 2",
"userscount": 0,
"createdDate": ISODate("2016-12-17T13:45:53.991Z")
},
// record 3
{
"_id": "a46asgasyas"
"content": "sample data set 3",
"userscount": 2,
"createdDate": ISODate("2016-12-15T13:45:53.991Z")
}
다음은 내가 시도 코드,
**Code snippet 1:**
new Sort(new Sort.Order(Sort.Direction.DESC, "createdDate"),
new Sort.Order(Sort.Direction.DESC, "userscount"));
**Code snippet 2:**
new Sort(new Sort.Order(Sort.Direction.DESC, "createdDate").and(,
new Sort.Order(Sort.Direction.DESC, "userscount")));
두 코드가 첫 번째 기준에 따라 정렬이됩니다 있습니다. 어떤 사람이 두 가지 정렬 기준으로 코드가 작동하지 않는 이유는 무엇입니까?
오타 ('users'는'userscount'가되어야합니다.)를 제외하고 쿼리는 정상적으로 작동합니다. 질의는 먼저 descDown 순서의 createdDate 필드에 의해 정렬되고, descDown 순서의 userscount 필드에 의해 각각의 createdDate 정렬 내에서 정렬됩니다. – Veeram
@Veeram 그래, 작동하지 않아. – Karthik
잘 동작합니다. 당신은 단지 충분한 문서가 없습니다. { "userscount": 1, "createdDate": ISODate ("2016-12-11T13 : 45 : 53.991Z") } "createdDate": ISODate ("2016-12-11T13 : 45 : 53.991Z") } { "userscount": 0, "createdDate": ISODate ("2016-12-11T13 : 45 : 53.991Z") }'. userscount desc로 정렬되는 방법에 유의하십시오. – Veeram