Skip to content

Find query on collection with two models using inheritance (discriminator) always returns all items in collection #11514

@reskume

Description

@reskume

Do you want to request a feature or report a bug?

Probably bug unless I didn't find the related part of the documentation.

What is the current behavior?

We updated mongoose from 5 to 6. Currently using the latest v6.2.5. The code has been updated according to the migration guide and everything is working fine except find queries that we use on a collection that is used by two models using the model's model.discriminator() function. We have a base model that basically defines base properties, methods and indexes. The two other child models only define a small number of custom properties, no indexes and some specific methods. Before updating to v6 with the latest v5, a find query that simply takes a search string and tries to find all items by e.g. serial number like{ serialNumber: 'sr1233' } has worked flawlessly. With v6, the query runs but always returns all items in the collection. I tried to run the same query on database level in 3T Studio and it works just fine. Also, nothing has changed on the models so far during the update process. So this seems to be related to mongoose v6. Is there something that I missed? If not, this is likely a bug.

Reproducible example repository

https://github.com/reskume/mongoose-discrm-findmany-bug

What is the expected behavior?

Running a query like { serialNumber: 'sr1233' } on a collection that is used by two models that inherit from a base model using
discriminator function always returns all items in the collection.

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

Node 16.13.2, Mongoose 6.2.5, MongoDB 5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    helpThis issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions