私のメッセージスキーマ:
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
});
受信者とユーザーをconsole.logすると、オブジェクトが返されます。次のようになります。
{ _id: 597f7eb1e5131d5a50e18d14,
updatedAt: 2017-07-31T19:02:09.035Z,
createdAt: 2017-07-31T19:02:09.035Z,
fullName: 'ria atayde',
email: '[email protected]',
password: '$2a$08$Kbkk69.8I9RQvTaRXy3nw.Oj.SEPhKPmhtI/ZWxIHyz2lgYiciVlC',
todos:
[ 597f801eab95955c1469bbfc,
597f8026ab95955c1469bbfd,
597f8030ab95955c1469bbfe ],
friendsIds: [ '597f7e3ce5131d5a50e18d13' ],
active: true,
__v: 0 }
これは私の質問です:
await MessageModel.find({ conversationId: { $in: conversationIdsByUser } })
.populate({path:'receiver' ,options: { lean: true}})
.populate({path:'sender' ,options: { lean: true}})
.lean();
私はすでにleanを使用しましたが、receiver._idなどの受信者と送信者のプロパティにアクセスできません。しかし、オブジェクトはありますか?
これは機能しますか?
await MessageModel.find({ conversationId: { $in: conversationIdsByUser } })
.populate('receiver sender', { lean: true}})
.lean();
lean
オプションなしでクエリを実行しようとするとどうなりますか?
await MessageModel.find({ conversationId: { $in: conversationIdsByUser } })
.populate('receiver sender');
マングースGitHubの誰かが、populateでleanを使用するのはまだバグがあるとコメントしているので、上記も試してみてください。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加