の配列で作業していないが、私のスキーマです:マングース移入がここた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