-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discriminators causing everything to be "unselected" when using "select" #5859
Comments
Thanks for the detailed repro, will fix. The |
awesome thanks so much |
Is it a different bug then? I have the same problem, I have a This problem happens on mongoos 4.13.18, on 5.x it seems to work correctly. |
@dimaip looks like this bug was fixed in 5.x then. Is there something that prevents you from upgrading? |
@vkarpov15 I already did, the upgrade process went smooth. |
I am attempting to use
.select
in a query with a discriminator model. The example below uses the projection to pull atextScore
(meant for use with a$text
query) but the bug is not specifically related to this use case.When making a
find
call, the returned objects do NOT havetrackField
oreventField
and they are selected out automatically without me specifying it.See Repro Script:
When you attach the debugger, it shows this query:
events.find({}, { fields: { score: { '$meta': 'textScore' }, __t: 1 } })
I imagine that the
__t: 1
is causing this.If I run
await Event.find({}).exec()
, the mongoose debugger showsevents.find({}, { fields: {} })
which is why normally everything is selected.The problem that this causes is that you can't run a $text query sorting by textScore on anything that has a discriminator without specifically projecting every single field in the schema.
Is there any way to override the
__t: 1
? I tried setting{__t: null}
but that didn't work. Or is there a mongodb projection operator that I'm not aware that might solve this problem?The text was updated successfully, but these errors were encountered: