'populate fails with refpath
I have a group document containing the "Users" field. I use refPath for dynamic addition. Fill does not work, an array of identifiers is returned.
Schema:
{
name: {
type: String,
required: true,
},
participants: [
{
type: mongoose.Schema.Types.ObjectId,
refPath: 'onModel',
}
],
onModel: {
type: String,
enum: ['User', 'UsersOffline'],
},
description: {
type: String,
},
},
{
versionKey: false,
timestamps: true,
},
);
Then I have my request :
async findOne(id: string) {
return await this.GroupModel.findById(id).populate('participants')
}
receive:
{
"participants": [
"60b5f9ba890d8625c076841b",
"60ec7117941ced002b950474",
"61e9498b84646a293c4d3718"
],
"_id": "62022f8af1f8624450066902",
"name": "Title",
"description": "<p>Description</p>",
"createdAt": "2022-02-08T08:53:30.735Z",
"updatedAt": "2022-02-08T09:00:14.582Z"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
