これを行う方法を理解しようとしています。基本的に、提出物の時間/日/月/年で並べ替えたいです。
それぞれsubmission
にcreated
、Mongoose Date オブジェクトを の形式で含むフィールドがあります"created" : ISODate("2013-03-11T01:49:09.421Z")
。find() 条件でこれと比較する必要がありますか?
これが私の現在のクエリです(FWIWのページネーションのためにカウントでラップしているので、その部分は無視してください):
getSubmissionCount({}, function(count) {
// Sort by the range
switch (range) {
case 'today':
range = now.getTime();
case 'week':
range = now.getTime() - 7;
case 'month':
range = now.getTime() - 31; // TODO: make this find the current month and # of days in it
case 'year':
range = now.getTime() - 365;
case 'default':
range = now.getTime();
}
Submission.find({
}).skip(skip)
.sort('score', 'descending')
.sort('created', 'descending')
.limit(limit)
.execFind(function(err, submissions) {
if (err) {
callback(err);
}
if (submissions) {
callback(null, submissions, count);
}
});
});
誰かがこれを理解するのを手伝ってくれますか? その現在のコードでは、時間範囲に関係なくすべての提出物が表示されるだけなので、明らかに何かを適切に行っていません