【发布时间】:2020-07-28 07:02:41
【问题描述】:
基本上我有 2 个架构。
用户和帖子。
用户有一个数组,其中包含来自帖子的 _ids。 并且 post 有一个属性,告诉他是否是一个活跃的帖子。 -> is_active。 所以,我想过滤至少有一个活跃帖子的用户。
用户架构
const UserSchema = new Schema(
{
name: {
type: String,
trim: true,
required: true
},
posts: [
{
type: Schema.Types.ObjectId,
ref: 'Post'
}
],
created_at: {
type: Date,
required: true,
default: Date.now()
}
}
)
export default mongoose.model<User>('User', UserSchema)
发布架构
const postSchema = new Schema(
{
name: String,
is_active: boolean
}
)
【问题讨论】:
标签: javascript node.js mongodb mongoose