【发布时间】:2021-11-17 11:36:18
【问题描述】:
我正在使用 mongoose 连接到 Mongo DB。
起初这是我的架构:
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const TestSchema = new Schema({
story: String,
seenByUser: [String],
medicationStage: {
type: String,
enum: [
"no-medication",
"just-after-medication",
"towards-end-of-medication",
],
required: true,
},
});
// Compile model from schema
const TestModel = mongoose.model("Test", TestSchema);
module.exports = {
Test: TestModel,
};
在这里您可以看到我有一个名为seenByUser 的字段,它是一个字符串数组,它是一个用户名数组。我正在设置一个数据聚合管道,我想在其中查看给定用户名获取该用户名的所有文档 不出现 @987654323 @ 大批。按medicationStage 分组。我无法创建此管道。请帮帮我。
【问题讨论】:
标签: javascript mongodb mongoose aggregation-framework mongoose-schema