这里阵列的工作是我的架构:猫鼬填充不具有的ObjectID
/** Schemas */
var profile = Schema({
EmailAddress: String,
FirstName: String,
LastName: String,
BusinessName: String
});
var convSchema = Schema({
name: String,
users: [{
type: Schema.Types.ObjectId,
ref: 'Profiles'
}],
conversationType: {
type: String,
enum: ['single', 'group'],
default: 'single'
},
created: {
type: Date,
default: Date.now
},
lastUpdated: {
type: Date,
default: Date.now
}
});
/** Models */
db.Profiles = mongoose.model('Profiles', profile);
db.Conversations = mongoose.model('ChatConversations', convSchema);
module.exports = db;
然后我尝试填充使用下面的代码(http://mongoosejs.com/docs/populate.html)用户:
db.Conversations.find(query).populate('users').exec(function (err, records) {
console.log(records);
});
这回records
但users
阵列作为空白阵列[]
。
我也试过的其他方式(http://mongoosejs.com/docs/api.html#model_Model.populate):
db.Conversations.find(query, function (err, records) {
db.Conversations.populate(records, {path: "users", select: "BusinessName"}, function (err, records) {
console.log(records);
});
});
结果相同。当我检查参考资料收集记录在那里。
任何想法这里有什么错?
一切似乎都对。并为我工作。不能看到任何错误 – chirag
哪一个工作? – Shreejibawa