Unable to use $in to query a nested discriminator key field together with a field from a child schema #13492
Closed
2 tasks done
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Prerequisites
Mongoose version
7.2.2
Node.js version
16.19.1
MongoDB server version
5
Typescript version (if applicable)
No response
Description
Forgive me for the complicated issue title - the problem is too specific.
I have a schema with a nested discriminator:
The following query does not work:
Mongoose throws an error:
The problem occurs with the specific combination:
This might be reproducible with operators other than $in - I never tried.
The problem does not occur with any of the following queries:
This also does not seem to happen if the discriminator is applied to the base schema instead of a nested one, or if there are no discriminators involved at all.
I also tried using strict: false, strictQuery: false - did not help.
Steps to Reproduce
Full code.
Expected Behavior
My understanding is that this query should work:
It should return all documents where "state.type" is "FOO" and "state.fieldFoo" is "test". Naturally, these will be documents whose "state" conforms to the
itemStateFooSchema
.The text was updated successfully, but these errors were encountered: