這裏陣列的工作是我的架構:貓鼬填充不具有的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