我已经在VisionModel.js和PictureModel.js中创建了以下两个模型Vision和Picture:
if (Game.Player.Character.GetVehicleIsTryingToEnter() == stretch && isEnteringCar == false)
{
isEnteringCar = true;
Game.Player.Character.Task.EnterVehicle(stretch, VehicleSeat.RightRear);
isEnteringCar = false;
}
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var visionSchema = new Schema({
title: String,
pictures: [{ type: Schema.Types.ObjectId, ref: 'Picture' }]
}, { timestamps: true });
module.exports = mongoose.model('Vision', visionSchema, 'visions');
现在,当我获得Vision文档时,我希望将所有图片附加到该文档中:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var pictureSchema = new Schema({
visionId: {type: Schema.Types.ObjectId, ref: 'Vision'},
formatOriginalUrl: String
}, { timestamps: true });
module.exports = mongoose.model('Picture', pictureSchema, 'pictures');
但是它不起作用,并返回图片的空数组
{
VisionModel
.findById("5cfbb1fbdc38da8f145a8d41")
.populate('pictures')
.exec(function (err, result) {
res.send(result);
});
}
我找不到错误,我们将不胜感激。