在我的Mongo数据库中,我有两个集合- speakers
和speeches
,我可以使用以下代码块“加入”它们(获取演讲者的演讲):
// I've already found the 'speaker' in the database
db.collection('speakers').aggregate([{
$match: { "uuid": speaker.uuid } },
{ $lookup: {
from: "speeches",
localField: "uuid",
foreignField: "speaker_id",
as: "speeches" } }
]).toArray();
它工作得很好,但我想按date
字段或title
字段对speeches数组进行排序,但我似乎没有做任何事情。我在这里看到的示例都没有完成我需要它们做的事情。我曾尝试在$lookup
块之后添加{ $sort: { "speech.title": -1 } }
,但没有任何效果。这有可能吗?
https://stackoverflow.com/questions/51885654
复制相似问题