javascript - Cannot access a property in mongoose populate? -
my message schema:
const messageschema = new schema({ conversationid: { type: schema.types.objectid, required: true }, body: { type: string, required: true }, seen: { type: boolean, default: false, }, sender: { type: schema.types.objectid, ref: 'usermodel' }, receiver: { type: schema.types.objectid, ref: 'usermodel' }, }, { timestamps: true });
when console.log receiver , user, returns object, it's there this:
{ _id: 597f7eb1e5131d5a50e18d14, updatedat: 2017-07-31t19:02:09.035z, createdat: 2017-07-31t19:02:09.035z, fullname: 'ria atayde', email: 'myloves@gmail.com', password: '$2a$08$kbkk69.8i9rqvtarxy3nw.oj.sephkpmhti/zwxihyz2lgyicivlc', todos: [ 597f801eab95955c1469bbfc, 597f8026ab95955c1469bbfd, 597f8030ab95955c1469bbfe ], friendsids: [ '597f7e3ce5131d5a50e18d13' ], active: true, __v: 0 }
this query:
await messagemodel.find({ conversationid: { $in: conversationidsbyuser } }) .populate({path:'receiver' ,options: { lean: true}}) .populate({path:'sender' ,options: { lean: true}}) .lean();
i used lean, still cannot access receiver , sender properties, e.g. receiver._id ? object there?
does work?
await messagemodel.find({ conversationid: { $in: conversationidsbyuser } }) .populate('receiver sender', { lean: true}}) .lean();
what happens when try query without lean
options?
await messagemodel.find({ conversationid: { $in: conversationidsbyuser } }) .populate('receiver sender');
you should try above well, since on mongoose github commented using lean populate still buggy.
Comments
Post a Comment