mongoose纲要参考

有可能有一个架构引用Mongo内的另一个架构?

我已经得到了下面的内容,我希望Line架构中的用户成为UserSchema中的用户

var UserSchema = new Schema({ name: {type: String, required: true}, screen_name: {type: String, required: true, index:{unique:true}}, email: {type: String, required: true, unique:true}, created_at: {type: Date, required: true, default: Date} }); var LineSchema = new Schema({ user: [UserSchema], text: String, entered_at: {type: Date, required: true, default: Date} }); var StorySchema = new Schema ({ sid: {type: String, unique: true, required: true}, maxlines: {type: Number, default: 10}, // Max number of lines per user title: {type: String, default: 'Select here to set a title'}, lines: [LineSchema], created_at: {type: Date, required: true, default: Date} }); var Story = db.model('Story', StorySchema); var User = db.model('User', UserSchema); 

       

网上收集的解决方案 "mongoose纲要参考"

对的,这是可能的

 var LineSchema = new Schema({ user: {type: Schema.ObjectId, ref: 'UserSchema'}, text: String, entered_at: {type: Date, required: true, default: Date} }); 

还有一句话,你为什么叫他们LineSchemaUserSchema ? 你可以叫他们LineUser ,他们代表一个行和一个用户毕竟:)