【发布时间】:2020-11-10 15:49:12
【问题描述】:
我有一个用户模式,其关注者数组如下所示,
const userSchema = new mongoose.Schema({
firstname: {
type: String,
required: true,
},
lastname: {
type: String,
required: true,
},
followers: [{ type: ObjectId, ref: "User" }],
following: [{ type: ObjectId, ref: "User" }],
});
当我查询用户列表时,我需要两个额外字段 isFollowing 和 isFollower (isFollowing存在于我的followers数组中,isFollower存在于followers数组中)
【问题讨论】: