我有2个MODELS
(不是模型和非模型模式)。
例如:
model1.js
const mongoose = require('mongoose')
const model1Schema = new mongoose.Schema({
serviceCenterId: {type: mongoose.Schema.ObjectId, required: true},
testId: {type: mongoose.Schema.ObjectId, required: true}
somethingElse: {...}
}, {timestamps: true})
module.exports = mongoose.model('Model1', model1Schema);
models2.js
const mongoose = require('mongoose')
const model2Schema = new mongoose.Schema({
//id of serviceCenterId is same as the MODEL1's serviceCenterId
//testId , same as testId of MODEL1
serviceCenterId: {type: mongoose.Schema.ObjectId, required: true},
testId: {type: mongoose.Schema.ObjectId, required: true},
//dummy datas....
}, {timestamps: true})
module.exports = mongoose.model('Model2', model2Schema);
我想在查询Model1
时填充Model2
(这些是模型,而不仅仅是模式)。
最好的方法是什么?