Skip to content
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

Prisma MongoDB Connector findMany query failing (CursorNotFound) #8389

Closed
ElectricReality opened this issue Jul 22, 2021 · 19 comments · Fixed by prisma/prisma-engines#2334
Closed
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: mongodb
Milestone

Comments

@ElectricReality
Copy link

Bug description

Querying a big collection, or getting all documents from a big collection results into a connection error thrown by Prisma.
Error Stack:

Failed to connect to the database. PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: 
Invalid `prisma.verifiedBots.findMany()` invocation:

  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawError { code: "unknown", message: "Command failed (CursorNotFound): cursor id 6919368312204108651 not found)" } })

Possible related Stack Overflow thread(s):

How to reproduce

  1. Connect to the MongoDB Connector
  2. Query a big collection (the collection on hand contains about 400 documents, with varying document sizes) using findMany()
  3. See error

Expected behavior

Prisma will throw PrismaClientUnknownRequestError2
Error Stack:

Failed to connect to the database. PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]: 
Invalid `prisma.verifiedBots.findMany()` invocation:

  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawError { code: "unknown", message: "Command failed (CursorNotFound): cursor id 6919368312204108651 not found)" } })

Prisma information

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["mongoDb"]
}

model dataset {
  id                   String   @id @default(dbgenerated()) @map("_id") @db.ObjectId
  clientid             String   @unique
  data                 String   @default("")
}

Environment & setup

  • OS: Windows 10 Pro 21H1
  • Database: MongoDB 5.0
  • Node.js version: v16.5.0

Prisma Version

prisma               : 2.27.0
@prisma/client       : 2.27.0
Current platform     : windows
Query Engine         : query-engine cdba6ec525e0213cce26f8e4bb23cf556d1479bb (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli cdba6ec525e0213cce26f8e4bb23cf556d1479bb (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core cdba6ec525e0213cce26f8e4bb23cf556d1479bb (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt cdba6ec525e0213cce26f8e4bb23cf556d1479bb (at node_modules\@prisma\engines\prisma-fmt-windows.exe)  
Default Engines Hash : cdba6ec525e0213cce26f8e4bb23cf556d1479bb
Studio               : 0.410.0
@ElectricReality ElectricReality added the kind/bug A reported bug. label Jul 22, 2021
@hinsxd
Copy link

hinsxd commented Jul 25, 2021

Same error here. The above error occurs when querying 100+ objects from a collection with 500 objects

@pantharshit00
Copy link
Contributor

Hmm, I wasn't able to reproduce. Anyone willing to share a sample dataset that I can use in a reproduction?

@pantharshit00 pantharshit00 added bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. topic: mongodb team/client Issue for team Client. labels Jul 26, 2021
@ElectricReality
Copy link
Author

Hmm, I wasn't able to reproduce. Anyone willing to share a sample dataset that I can use in a reproduction?

Heyo! Here's a dataset that i generated, which threw the error above:
Hastebin
Insert the dataset above to your database.

The schema is as follows:

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["mongoDb"]
}

model dataset {
  id   String @id @default(dbgenerated()) @map("_id") @db.ObjectId
  data String
}

@pantharshit00
Copy link
Contributor

pantharshit00 commented Jul 28, 2021

Thanks for the dataset, I can reproduce this issue with that.

code/reproductions/issue_8389 is 📦 v1.0.0 via  v14.17.0
❯ yarn start
yarn run v1.22.5
$ ts-node main.ts
(node:14052) UnhandledPromiseRejectionWarning: Error:
Invalid `prisma.dataset.findMany()` invocation:


  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawError { code: "unknown", message: "Command failed (CursorNotFound): cursor id 3342870519408957573 not found)" } })
    at cb (C:\Users\harshit\code\reproductions\issue_8389\node_modules\@prisma\client\runtime\index.js:34804:17)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at main (C:\Users\harshit\code\reproductions\issue_8389\main.ts:6:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14052) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing ins
ide of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To termin
ate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodej
s.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:14052) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Terminate batch job (Y/N)?
^C
import { PrismaClient } from "@prisma/client";

async function main() {
  const prisma = new PrismaClient();

  const data = await prisma.dataset.findFirst();
  console.log(data);
  prisma.$disconnect();
}

main();
datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["mongoDb"]
}

model dataset {
  id   String @id @default(dbgenerated()) @map("_id") @db.ObjectId
  data String
}

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. process/candidate and removed bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. labels Jul 28, 2021
@hinsxd
Copy link

hinsxd commented Aug 1, 2021

Can confirm the query works normally up to v2.26.0. Only fails in v2.27.0 and v2.28.0

@Krzysztof-Dziardziel
Copy link

Krzysztof-Dziardziel commented Sep 1, 2021

Hey.
Did You find a solution for this issue? Everything works on my test environment but when on production I get error:

PrismaClientUnknownRequestError3 [PrismaClientUnknownRequestError]: 
gql_1  | Invalid `prisma.twilio_users.findMany()` invocation:
gql_1  | 
gql_1  | 
gql_1  |   Error occurred during query execution:
gql_1  | ConnectorError(ConnectorError { user_facing_error: None, kind: RawError { code: "unknown", message: "Command failed (CursorNotFound): cursor id 316062295884969514 not found)" } })
gql_1  |     at cb (/app/node_modules/@prisma/client/runtime/index.js:36067:17)
gql_1  |     at runMicrotasks (<anonymous>)
gql_1  |     at processTicksAndRejections (internal/process/task_queues.js:95:5)
gql_1  |     at async emergencyCallAllUsers (/app/helpers/emergencyCallAllUsers.js:9:29)

Prisma version: 2.24.1

@jeremiahfallin
Copy link

Also getting this issue with version 2.30.3 and when I downgrade to 2.26 I get this issue instead: #6998

@dimaip
Copy link

dimaip commented Sep 16, 2021

Prisma 3.0.2 here. Taking more than 100 records yields this error.

@MahmoudAlawdh
Copy link

I have the same issue,
Prisma 3.1.1

@monapasan
Copy link

any update on this? Experiencing the same issue in 3.1.1

@redbaron76
Copy link

redbaron76 commented Oct 6, 2021

Still present in the brand new 3.2.0 release.

My implementation fails when I start a cursor-based infinite pagination.

@dimaip
Copy link

dimaip commented Oct 8, 2021

Hate to be that guy whining on Github issues, but the fact that there's be no comment in 3 months from core developers on such major issue is kinda frightening.

@redbaron76
Copy link

True. But I think is something related explicitly to MongoDB implementation which is a topic relatively new in the Prisma world and still in experimental stage.

@nikolasburk
Copy link
Member

Seems like this is the same error I've been describing here: #9650 I'm not yet closing my issue since I'm not sure it's really a duplicate but wanted to at least mention this here.

@Weakky
Copy link
Member

Weakky commented Oct 8, 2021

Hey folks,

I spent some time investigating this issue today. I'm now waiting for confirmation from the MongoDB folks but it seems that the error comes from the Rust driver itself.

I created an issue on their repo that you can find here: mongodb/mongo-rust-driver#482

I'll try to keep you up-to-date with further news once I know more

@redbaron76
Copy link

In all my tests, findMany() seems to fail in any subsequent query on the same dataset when applying select: {...} clause which relates to some collections with 100+ records inside. It doesn't matter if cursor: {id: ...} is present or not in the query. Maybe this helps.

@Weakky
Copy link
Member

Weakky commented Oct 12, 2021

In all my tests, findMany() seems to fail in any subsequent query on the same dataset when applying select: {...} clause which relates to some collections with 100+ records inside. It doesn't matter if cursor: {id: ...} is present or not in the query. Maybe this helps.

Hey @redbaron76, yes the reason for that problem is laid out in this issue mongodb/mongo-rust-driver#482

On that note, a fix on the MongoDB Rust driver was just pushed, effectively closing mongodb/mongo-rust-driver#482. I've been told a new version of the driver would be released tomorrow, meaning that this issue might be fixed in time for the next Prisma release.

@redbaron76
Copy link

Is there already a scheduled date for the next Prisma release?

@Weakky
Copy link
Member

Weakky commented Oct 19, 2021

I can confirm the bug fix will be included in the next release.

@redbaron76 The next release should be today.

Thanks for the reports folks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: mongodb
Projects
None yet
Development

Successfully merging a pull request may close this issue.