【发布时间】:2021-07-29 21:33:13
【问题描述】:
我有一个这样的 customerDocument 架构:
const customerDocumentSchema = new mongoose.Schema(
{
title: { type: String, required: true },
section: { type: String },
description: { type: String, required: true },
customer: { type: mongoose.Schema.Types.ObjectId },
documentKey: { type: String },
},
{ timestamps: true }
);
我需要根据section 对返回结果进行分组,如下所示:
[
section1:[{title:'',description:'',customer:'',documentKey:''},{},{}...],
section2:[{title:'',description:'',customer:'',documentKey:''},{},{}....],
sectionN:[....]
]
sections 只是不同的字符串,结果也应该用 customer 过滤,这是一个猫鼬 ID。我应该如何实现这个?
【问题讨论】:
标签: mongodb mongoose mongodb-query aggregation-framework mongoose-schema