【发布时间】:2016-01-02 16:30:58
【问题描述】:
我有一个 Mongo 消息集合,如下所示:
{
'recipients': [],
'unRead': [],
'content': 'Text'
}
Recipients 是用户 id 的数组,unRead 是尚未打开邮件的所有用户的数组。这按预期工作,但我需要查询所有消息的列表,以便它返回前 20 个结果,优先考虑未读的结果,例如:
db.messages.find({recipients: {$elemMatch: userID} })
.sort({unRead: {$elemMatch: userID}})
.limit(20)
但这不起作用。根据结果是否符合特定标准来确定结果优先级的最佳方法是什么?
【问题讨论】:
标签: mongodb mongodb-query aggregation-framework