开发者社区 问答 正文

mongoose如何保证填充的数据是唯一的

const UserSchema = new Schema(
  {
    userId: String,
    userName: String,
    password: String,
    friendList: [
      {type: Schema.Types.ObjectId, ref: 'User'}
    ],
  },
  {
    timestamps: true
  }
)

请问如何能保证friendList数组内的用户是唯一的呢

展开
收起
xiawang1024 2021-10-14 17:09:20 11908 分享 版权
0 条回答
写回答
取消 提交回答
问答地址: