Schema({ email: { type: String, }, }); const ContactModel = mongoose.model('Contact', ContactSchema); const PersonSchema = new mongoose.Schema({ name: { type: String, }, contacts: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Contact' }], }); const PersonModel = mongoose.model...
Themongoose-autopopulatemodule exposes a single function that you can pass toMongoose schema'splugin()function. constschema=newmongoose.Schema({populatedField:{type:mongoose.Schema.Types.ObjectId,ref:'ForeignModel',// The below option tells this plugin to always call `populate()` on// `populated...
dropDatabase(); const userSchema = new Schema({ name: String }); const User = mongoose.model('User', userSchema); const buildingSchema = new Schema({ ownerId: { type: Schema.ObjectId, ref: 'User' } }); const Building = mongoose.model('Building', buildingSchema); const officeSchema...