I have two model User and ChatRoom.
In User model has chatrooms field like this:
@Prop({ type: [{ type: mongoose.Schema.Types.String, ref: ‘ChatRoom’ }], defaul: })
chatrooms: string;
In ChatRoom model has members field like this:
@Prop({ type: [{ type: mongoose.Schema.Types.ObjectId, ref: ‘User’ }], default: })
members: string;
My original query:
this.userModel
.findById(userId)
.select('name username chatrooms')
.populate({
path: 'chatrooms',
select: 'name roomImage members',
});
But if I change my query like below
this.userModel
.findById(userId)
.select('name username chatrooms')
.populate({
path: 'chatrooms',
select: 'name roomImage members',
populate: {
path: 'members',
select: 'name username'
},
});
I will lose the first member in the test_room2 which has the _id: 64d08bf77c1dbd17e493acd7
