1 回答
TA贡献1862条经验 获得超7个赞
数据方面的每个管道都应该是数组的元素
metadataStage := bson.D{
{"$facet", bson.D{
{"metadata", bson.A{
bson.D{{"$group", bson.D{
{"_id", nil},
{"total", bson.D{{"$sum", 1}}}}}}, // get number of documents that matches the all above conditions
}},
{"data", bson.A{
//bson.D{{"$sort", sortStage}}, // sort by field and direction
bson.D{{"$skip", skip}}, // skip number of documents
bson.D{{"$limit", limit}}}}}, // limit them
}}
或者,您可以写清楚您正在为方面声明管道的阶段。
metadataStage := bson.D{
{"$facet", bson.D{
{"metadata", mongo.Pipeline{
bson.D{{"$group", bson.D{
{"_id", nil},
{"total", bson.D{{"$sum", 1}}}}}}, // get number of documents that matches the all above conditions
}},
{"data", mongo.Pipeline{
//bson.D{{"$sort", sortStage}}, // sort by field and direction
bson.D{{"$skip", skip}}, // skip number of documents
bson.D{{"$limit", limit}}}}}, // limit them
}}
- 1 回答
- 0 关注
- 127 浏览
添加回答
举报