【发布时间】:2019-01-25 14:22:19
【问题描述】:
我正在尝试使用 expressjs 和 mongodb 按喜欢的数量对帖子进行排序。
get "postsByLikes/:category", (req, res, next) ->
category = req.params.category
db.posts.aggregate([
{$match:
type: "post"
category: category}
{$project:
likesCount:
$size: "like"}
{"$sort":
"likesCount": -1}
]).toArray (err, posts) ->
res.send(posts)
这个查询有什么问题?
【问题讨论】:
-
我们怎么知道?请说明您需要什么
-
你错过了 $ 吗?应该是
$size:"$like" -
@Veeram 谢谢这就是问题所在!随时发布答案,我会将其标记为正确。
标签: javascript mongodb coffeescript