Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Mongoose用户模式设计和ref中的帖子数组_Node.js_Mongodb_Mongoose - Fatal编程技术网

Node.js Mongoose用户模式设计和ref中的帖子数组

Node.js Mongoose用户模式设计和ref中的帖子数组,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我的模式设计如下。我有一个posts数组,它引用post模型。把它放在用户模式中是个好主意,还是我不应该把它包括在内,因为随着用户添加他们的帖子,它总是在增长。我想我应该只把AccessToken放在引用中,而不是帖子中。我想得对吗 var UserSchema = new Schema({ username: { type: String, unique: true, required: true, lowercase: true, trim: tr

我的模式设计如下。我有一个posts数组,它引用post模型。把它放在用户模式中是个好主意,还是我不应该把它包括在内,因为随着用户添加他们的帖子,它总是在增长。我想我应该只把AccessToken放在引用中,而不是帖子中。我想得对吗

var UserSchema = new Schema({
  username: {
    type: String,
    unique: true,
    required: true,
    lowercase: true,
    trim: true
  },
  encrypted_password: {
    type: String,
    required: true
  },
  salt: {
    type: String,
    required: true
  },
  email: {
    type: String,
    unique: true,
    required: true,
    lowercase: true,
    trim: true
  },
  mobile: {
    type: Number,
    unique: true
  },
  bio: {
    type: String
  },
  created: {
    type: Date,
    default: Date.now
  },
  access_tokens: [{type: Schema.Types.ObjectId, ref: 'AccessToken'}],
  posts: [{type: Schema.Types.ObjectId, ref: 'Post'}]
}, { collection: 'users' });

您应该有一个单独的POST集合,但是您应该将
access\u令牌
保留在用户架构中。一个很好的理由,你可能会考虑将帖子分成自己的集合,有很多用例,你会查询只是职位。但是,使用
access\u令牌
,它们将始终绑定到用户

太长,读不下去了 帖子应该有自己的模式

访问令牌应位于用户架构中

希望有帮助