3
我碰到下面的代码行,我听不懂,虽然有很多教程,让有关的populate
实例的信息却是没有解释究竟它means.Here是一个例子填充猫鼬是什么意思?
var mongoose = require('mongoose'), Schema = mongoose.Schema
var PersonSchema = new Schema({
name : String,
age : Number,
stories : [{ type: Schema.ObjectId, ref: 'Story' }]
});
var StorySchema = new Schema({
_creator : {
type: Schema.ObjectId,
ref: 'Person'
},
title : String,
fans : [{ type: Schema.ObjectId, ref: 'Person' }]
});
var Story = mongoose.model('Story', StorySchema);
var Person = mongoose.model('Person', PersonSchema);
Story.findOne({ title: /Nintendo/i }).populate('_creator') .exec(function (err, story) {
if (err) ..
console.log('The creator is %s', story._creator.name);
// prints "The creator is Aaron"
})
你可以添加代码到你的问题? –
填充通常用于在查询http://mongoosejs.com/docs/2.7.x/docs/populate.html时填充ref对象属性 –