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
import{Schema,model,Document,Types}from'mongoose'// `Parent` represents the object as it is stored in MongoDBinterfaceParent{child?: Types.ObjectIdname?: string}interfaceChild{name: string}interfacePopulatedParent{child: Child|null}constParentModel=model<Parent>('Parent',newSchema({child: {type: 'ObjectId',ref: 'Child'},name: String}))constchildSchema: Schema=newSchema({name: String})constChildModel=model<Child>('Child',childSchema)// Populate with `Paths` generic `{ child: Child }` to override `child` pathParentModel.find({}).populate<{child: Child}>('child').orFail().then(parents=>{// Property 'name' does not exist on type 'ObjectId'.parents.map(p=>p.child.name)})
I get Property 'name' does not exist on type 'ObjectId' on p.child.name
...Or do you do something else for multiple results?
This is on mongoose 6.0.13
The text was updated successfully, but these errors were encountered:
Discussed in #11014
Originally posted by falukropp November 24, 2021
Starting with https://mongoosejs.com/docs/typescript/populate.html but using find instead of findOne, should not the following work?
I get
Property 'name' does not exist on type 'ObjectId'
onp.child.name
...Or do you do something else for multiple results?
This is on mongoose 6.0.13
The text was updated successfully, but these errors were encountered: