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

MongoDB: 2 queries for findUnique lead to error #8276

Closed
fullStackDataSolutions opened this issue Jul 14, 2021 · 3 comments
Closed

MongoDB: 2 queries for findUnique lead to error #8276

fullStackDataSolutions opened this issue Jul 14, 2021 · 3 comments
Assignees
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: mongodb
Milestone

Comments

@fullStackDataSolutions
Copy link

fullStackDataSolutions commented Jul 14, 2021

Bug description

When two queries come in at the same time that execute a prisma.findUnque on our Mongo DB we get the following error:

[7/13/2021] [1:39:22 PM] [auth.ts] › ✖  error     Error: Error occurred during query execution: 
ConnectorError(ConnectorError { user_facing_error: Some(KnownError { message: "Inconsistent column data: Failed to convert 'List([String(\"60db4f12fcb8ff3c591c52eb\"), String(\"60db4f12fcb8ff3c591c52eb\")])' to 'ObjectId'.", meta: Object({"message": String("Failed to convert 'List([String(\"60db4f12fcb8ff3c591c52eb\"), String(\"60db4f12fcb8ff3c591c52eb\")])' to 'ObjectId'.")}), error_code: "P2023" }), kind: ConversionError(Failed to convert 'List([String("60db4f12fcb8ff3c591c52eb"), String("60db4f12fcb8ff3c591c52eb")])' to 'ObjectId'.) })
    at /graphql-gateway/node_modules/@prisma/client/runtime/index.js:28913:19
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

How to reproduce

We have a front end app that is sending two different queries to the backend, the backend firs gets the user with a findUnqiue query. the queries are being pooled. We were able to get it working by using findFirst.

Expected behavior

Prisma should be able to find a unique value.

Prisma information

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

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

model DbUser {
   id    String @id @default(dbgenerated()) @map("_id") @db.ObjectId
   createdAt DateTime @default(now())
   updatedAt DateTime @updatedAt
  firstName String?
  lastName String?
  email String?
  image String?
  phone String?
  count Int?
  role String

  @@map("dbUsers")
}

model User {
  id    String    @id @default(dbgenerated()) @map("_id") @db.ObjectId
  username String?
  email String    @unique
  redirect String?
  name String?
  locale String?
  image String?
  emailVerified Boolean

  @@map("users")
}
const dashboardUser = await prisma.dbUser.findFirst({
        where: { id: decodedToken.Id },
      });

Environment & setup

  • OS: Linux
  • Database: MongoDB
  • Node.js version: 12.22.1

Prisma Version

2.27.0
@fullStackDataSolutions fullStackDataSolutions added the kind/bug A reported bug. label Jul 14, 2021
@matthewmueller matthewmueller added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. labels Jul 14, 2021
@matthewmueller
Copy link
Contributor

matthewmueller commented Jul 14, 2021

Just to confirm, you're running findUnique on the id, not on a @unique field like email?

Right now we don't support managing @unique indexes, so you have to create them outside of Prisma. See this issue for more context.

But if you're running it on the @id, that seems like a separate issue.

@fullStackDataSolutions
Copy link
Author

fullStackDataSolutions commented Jul 14, 2021 via email

@dpetrick dpetrick self-assigned this Jul 14, 2021
@matthewmueller matthewmueller added this to the 2.28.0 milestone Jul 14, 2021
@janpio janpio changed the title Mongo integration 2 queries for findUnique error MongoDB: 2 queries for findUnique lead to error Jul 15, 2021
@dpetrick
Copy link
Contributor

Fixed in 2.28.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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: mongodb
Projects
None yet
Development

No branches or pull requests

4 participants