mongoose模型中同一架构中的Ref字段

mongoose模型中同一架构中的Ref字段,mongoose,mongoose-schema,mongoose-populate,Mongoose,Mongoose Schema,Mongoose Populate,我有以下模式:- 用户是主模式,下面的“following”是一个数组字段。在“following”架构中,“user”是对“user”架构的“ref”。是否可以在同一模式中引用 请阅读我的问题评论 const FollowersSchema = new mongoose.Schema( { user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', // Is it possible to use

我有以下模式:-

用户是主模式,下面的“following”是一个数组字段。在“following”架构中,“user”是对“user”架构的“ref”。是否可以在同一模式中引用

请阅读我的问题评论

const FollowersSchema = new mongoose.Schema(
  {
    user: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'User',   // Is it possible to use ref in the same Schema? Cause 'UserSchema as User' is the current parent Schema
    },
  },
  {
    timestamps: true,
  }
);

const FollowingSchema = new mongoose.Schema(
  {
    user: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'User',
    },
  },
  {
    timestamps: true,
  }
);

const UserSchema = new mongoose.Schema(
  {
    full_name: {
      type: String,
      default: '',
    },
    dp: {
      type: String,
    },
    cover: {
      type: String,
    },
    view: {
      type: Number,
      default: 0,
    },
    email: {
      type: String,
    },
    bio: {
      type: String,
    },
    relationship: {
      type: String,
    },
    gender: {
      type: String,
    },
    social: [SocialSchema],
    education: [EduSchema],
    following: [FollowingSchema],
    followers: [FollowersSchema],
  },
  {
    timestamps: true,
  }
);