mongoose连表查询3(一对多)

var UserSchema = new Schema({
    name  : { type: String, unique: true },
    posts : [{ type: Schema.Types.ObjectId, ref: 'Post' }] }); var User = mongoose.model('User', UserSchema); var PostSchema = new Schema({ poster : { type: Schema.Types.ObjectId, ref: 'User' }, comments : [{ type: Schema.Types.ObjectId, ref: 'Comment' }], title : String, content : String });

转载于:https://www.cnblogs.com/jay--zhang/p/6437486.html

你可能感兴趣的:(数据库,数据结构与算法)