我想使用猫鼬nodejs加入两个集合,但是我被困住了,
const mongoose = require('mongoose');
const gameSchema = new mongoose.Schema({
providerName:{
type: String
},
gamesSettings :[{
type: mongoose.Schema.Types.ObjectId,
ref: 'games_setting'
}]
});
module.exports = mongoose.model('gamesDetails', gameSchema);
This is the route :
router.get('/', async (req, res)=>{
try {
const gamesDetails1 = await joinCollection.find();
res.json(gamesDetails1);
//res.render('./games/gamesetting', { data: gamesDetails1 });
} catch (e) {
res.json({ message: e });
}
});
我得到的回应是空的。
答案 0 :(得分:0)
我不确定我是否正确理解了您的问题,但是我认为您需要执行的是填充gameeSetting的查询。答案是:
const details = await gamesDetails.find().populate('gamesSettings');