You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there an existing issue that is already proposing this?
I have searched the existing issues
Is your feature request related to a problem? Please describe it
Following the tutorial in the official NestJs documentation for MongoDB
A populated property can be either a ObjectId or document so handling the populating property can be a little messy.
Also insertions and update with ObjectId seems to not be possible
Although this can be resolved by using union type between ObjectId and the entity, the Entity doesn't have _id in them, which although seems minor enough, _id of the populated document is cannot be fetched without bypassing the typescript type checking.
Describe the solution you'd like
Giving the populated Property it's own type seems to be a good starting point.
I am trying to setup my schema files correctly according to the official Mongoose documentation, but I am stuck as well. I'll go with a union type combined with a manual check child == null || child instanceof ObjectId to safely handle the structures, since the generic given by populate() is ignored by @nestjs/mongoose.
Put ID at the end of the name of the id value you defined in the schema and create a virtual value with the previous name. Then populate the virtual type and give the type you want as generic type. The usage is not that better but I think it works more compatible with typescript.
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
Following the tutorial in the official NestJs documentation for MongoDB
A populated property can be either a ObjectId or document so handling the populating property can be a little messy.
Also insertions and update with ObjectId seems to not be possible
Although this can be resolved by using union type between ObjectId and the entity, the Entity doesn't have _id in them, which although seems minor enough, _id of the populated document is cannot be fetched without bypassing the typescript type checking.
Describe the solution you'd like
Giving the populated Property it's own type seems to be a good starting point.
The following is how i would imagine it to be:
export type PopulatedEntity<T> = Types.ObjectId | (T & { _id: Types.ObjectId; });
This can be implemented in the @Schema entity as:
@Prop({ type: mongoose.Schema.Types.ObjectId, ref: 'Owner' }) owner: PopulatedEntity<Owner>;
Teachability, documentation, adoption, migration strategy
No response
What is the motivation / use case for changing the behavior?
Following are the use cases where the default implementation cause an issue:
The text was updated successfully, but these errors were encountered: