Can a getter be used in a query condition? #10914
Answered
by
vkarpov15
vineetdigit
asked this question in
Q&A
-
In the following example, 'type' is a getter defined on the Post Schema. 'type' is of type string that the getter computes after looking at one or more fields of the document. Even though the database contains a post document with valid postId that will compute type to "comment", the following query always returns null. I'm wondering if mongoose supports using a getter in the query document?
|
Beta Was this translation helpful? Give feedback.
Answered by
vkarpov15
Oct 23, 2021
Replies: 1 comment 1 reply
-
Unfortunately not. Since virtuals aren't stored in MongoDB, you can't use virtuals in query filters. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
vineetdigit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately not. Since virtuals aren't stored in MongoDB, you can't use virtuals in query filters.