populating virtual with same name as existing path #10765
-
Hello, I have a schema that contains a path "authoredBy" that has type Number.
I want this path populated with a document from another collection, and I'm defining a virtual as follows
This results in error message as If I change the virtual name to something else like "authorInfo", then it works. But then I have two paths in the populated document (authoredBy and authorInfo) which is acceptable, but not ideal. I want to have same experience as conventionally populating paths that have type ObjectId in which the pathname is simply populated with a document from another collection. Is this possible with virtual population? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Unfortunately not with virtual populate. There's no way for a path to be both a real path and a virtual in a schema. Why not just use conventional populate? const SomeSchema = new Schema(
{
authoredBy: {
type: Number,
required: true,
ref: 'Author'
},
.....
}); |
Beta Was this translation helpful? Give feedback.
Unfortunately not with virtual populate. There's no way for a path to be both a real path and a virtual in a schema.
Why not just use conventional populate?