这是我的数据结构
{
"_id" : ObjectId("57f37f18517f72bc09ee7632"),
"name" : "testdata",
"createdBy" : "57f1fdef1d3c40141617d215",
"transitionEnabled" : false,
"status" : "active",
"createdDateTime" : ISODate("2016-10-04T10:06:16.195Z"),
"accounts" : [
"57f37f75517f72bc09ee7634"
],
"deliverables" : [],
"risks" : [],
"issues" : {
"_id" : ObjectId("57f38398517f72bc09ee7680"),
"title" : "test",
"description" : "Delay in testing due to issues with Provider Finder dataload in the test region. This has impacted the production release planned for Sep 30th",
"plannedStartDate" : ISODate("2016-09-01T00:00:00.000Z"),
"plannedEndDate" : ISODate("2016-10-30T00:00:00.000Z"),
"assignedTo" : "57f375ea517f72bc09ee762a",
"createdBy" : ObjectId("57f375ea517f72bc09ee762a"),
"likes" : 0,
"createdDateTime" : ISODate("2016-10-04T10:25:28.301Z"),
"status" : "open",
"stakeholders" : [],
"__v" : 0,
"lastUpdatedTime" : ISODate("2019-11-15T09:19:06.279Z")
},
"__v" : 0
}
我想按组织选择所有问题组,我想对这些数据实现排序、限制和跳过(子数组只从上面发出数据)。为此,我尝试了以下代码
db.organizations.aggregate([ { "$lookup" : { "from" : "issues", "localField" : "issues.str", "foreignField" : "_id.str", "as" : "issues" } }, {$sort: {weight: -1, "issues.lastUpdatedTime": 1}} { $group: { _id: "$issues", }, },])
我得到的结果如下。
如何对以下查询进行排序、设置限制和跳过?查询返回的结果也被附加。
但我不需要在上面的结果中显示的外部id字段。请帮我解决这个问题。
最佳答案
首先$展开问题子数组,并使用其结果应用排序、跳过和限制