MongoDB Connector generates queries which do not take advantage of indices. #17396
Labels
bug/1-unconfirmed
Bug should have enough information for reproduction, but confirmation has not happened yet.
kind/bug
A reported bug.
team/client
Issue for team Client.
topic: in
topic: mongodb
topic: performance/queries
topic: performance
Milestone
Bug description
Overview
We noticed while developing a new feature using Prisma & MongoDB Connector, that simple ID
$in
queries were taking 450ms+ to query a single ID.The
_id
field is of course indexed in MongoDB, so you'd expect the query Prisma generates to be one which will take advantage of indexing, however...The docs for
$expr
state:So here, our
$expr
takes an array to match$in
, and results in aCOLLSCAN
through our entire collection:If we rewrite our
$match
query to be much simpler and not use$expr
, it will successfully make use of the indices:Questions / Observations
@id
prisma property is also an@@index
.$expr
? Why is the generated query using$expr
?How to reproduce
prisma
client using the supplied example andmongodb
connector.typescript
query.mongo
query results in aCOLLSCAN
.Expected behavior
Should take advantage of
_id
indices so that query performance is fast.Prisma information
Prisma Collection
Calling Code
Prisma Generated Aggregate Pipeline Stage
Environment & setup
prisma
version: 4.4.0mongo
version: 4.2.23Prisma Version
The text was updated successfully, but these errors were encountered: