|
Starting with https://mongoosejs.com/docs/typescript/populate.html but using find instead of findOne, should not the following work? import {Schema, model, Document, Types} from 'mongoose'
// `Parent` represents the object as it is stored in MongoDB
interface Parent {
child?: Types.ObjectId
name?: string
}
interface Child {
name: string
}
interface PopulatedParent {
child: Child | null
}
const ParentModel = model<Parent>(
'Parent',
new Schema({
child: {type: 'ObjectId', ref: 'Child'},
name: String
})
)
const childSchema: Schema = new Schema({name: String})
const ChildModel = model<Child>('Child', childSchema)
// Populate with `Paths` generic `{ child: Child }` to override `child` path
ParentModel.find({})
.populate<{child: Child}>('child')
.orFail()
.then(parents => {
// Property 'name' does not exist on type 'ObjectId'.
parents.map(p => p.child.name)
})I get ...Or do you do something else for multiple results? This is on mongoose 6.0.13 |
Answered by
falukropp
Dec 1, 2021
Replies: 2 comments
|
Just noticed the same thing. I think this is likely worthy of an issue. I suspect either the docs need to be updated or the Types need to be fixed. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
vkarpov15 created an issue for it #11027