最好的办法还是写一个真实的项目,从博客项目开始。
UserSchema = new Schema({
...
contacts:[]
});
ContactSchema = new Schema({
...
owner: {
type: Schema.ObjectId,
required: true,
index: true
}
});
ContactSchema = new Schema({
...
owner: {
type: Schema.ObjectId,
ref: ‘user’
}
});
ContactSchema.find({}).populate(‘owner’).exec(callback);
从分库分表的角度讲