Javascript 如何实现Mongoose黑名单模式?

Javascript 如何实现Mongoose黑名单模式?,javascript,mongoose,mongoose-schema,Javascript,Mongoose,Mongoose Schema,我有两个模式,Person和Message,如何实现Mongoose黑名单模式 我的意思是,当一个用户不喜欢他的消息时,他可以阻止另一个用户。 我是否需要一个新的架构来提高性能? 请举例说明 人: const personSchema = new Schema({ _id: Number, tok: {type: String, required: true, unique: true}, name: String, pwd: String, gender: String,

我有两个模式,
Person
Message
,如何实现Mongoose黑名单模式

我的意思是,当一个用户不喜欢他的消息时,他可以阻止另一个用户。
我是否需要一个新的架构来提高性能?
请举例说明

人:

const personSchema = new Schema({
  _id: Number, 
  tok: {type: String, required: true, unique: true},
  name: String,
  pwd: String,
  gender: String,
});
const messageSchema = new Schema({
  userId: {type: Number, ref: 'Person'},
  text: String,
  voice: String,
  senderId: Number,
});
消息:

const personSchema = new Schema({
  _id: Number, 
  tok: {type: String, required: true, unique: true},
  name: String,
  pwd: String,
  gender: String,
});
const messageSchema = new Schema({
  userId: {type: Number, ref: 'Person'},
  text: String,
  voice: String,
  senderId: Number,
});

您可以向应列入黑名单的用户添加一组引用

const personSchema=新模式({
_身份证号码:,
tok:{type:String,required:true,unique:true},
名称:String,
pwd:String,
性别:String,,
黑名单:[{
类型:mongoose.Schema.Types.ObjectId,
ref:'user'//与mongoose.model()的第一个参数相同
}]

});

我是否需要
ref:'user'
?因为我只有person和MessageSchemath,它只告诉mongoose将objectId与哪个集合关联。除非你想把整个黑名单上的用户文档都存储在那里。这一决定最终归结为您认为有多少用户会被阻止,以及您愿意接受多大程度的复制。ref可以指向personSchemas存储在的同一个集合,实际db中存储的唯一内容是objectId。