【发布时间】:2016-01-16 15:26:55
【问题描述】:
我有一个集合,其中有一个名为 timestamp 的字段,其中包含日期对象。我有这个问题:
db.articles.find({
timestamp:{
'$lte':new Date(),
'$gte': //Something to get the last week's date
}
})
如果可能的话,我可以按此文档中数组的长度对这些返回的文档进行排序吗?这是架构:
section: String,
title: String,
abstract: String,
url: String,
image: {
url: String,
caption: String
},
votes:{
up: [ObjectID],
down: [ObjectID]
},
comments:[ObjectID],
timestamp: Date
我想按votes.up 和votes.down 的差异大小对返回的对象进行排序。现在我在 Javascript 中对返回的对象进行排序,这实际上返回了数据。
【问题讨论】:
标签: javascript mongodb mongoose