question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Simple MongoDB query takes over 30 seconds to execute

See original GitHub issue

Bug description

I have GoogleOAuth authentication through Passport in my Express server, and I run the .upsert() function to check if a user exists, otherwise I create one. However it appears this query is taking upwards of 30 seconds, meaning the user is stuck on the OAuth consent screen for about that long waiting to be logged in. It seems this is happening on most queries I make, however I’ve only thoroughly tested with this scenario.

How to reproduce

  1. Set up basic auth template with passport google oauth or copy from a demo repo I made and adjust to use Prisma accordingly.
  2. Navigate to the login route which will eventually execute the upsert() function
  3. Wait…

Prisma information

Schema file

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

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

model User {
  id          String @id @default(dbgenerated()) @map("_id") @db.ObjectId
  googleId    String @unique
  displayName String
  avatarUrl   String
  role        String @default("free")
}
// query looks like this, however I've tried making a few adjustments with no success
      const user = await prisma.user.upsert({
        where: {
          googleId: profile.id, 
        },
        update: {},
        create: {
          googleId: profile.id,
          displayName: profile.displayName,
          avatarUrl: profile.photos[0].value,
        },
      });

Environment & setup

  • OS: Windows 11
  • Database: MongoDB (Atlas)
  • Node.js version: 16.13.1

Prisma Version

3.7.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Maxson52commented, Jan 7, 2022

Can confirm, the cluster was causing the problem. Thanks for the support in finding out the issue here!

1reaction
Maxson52commented, Jan 6, 2022
    // generate timestamp
    const timestamp = new Date().toTimeString();
    const users = await prisma.user.findMany();

    // generate timestamp
    const timestamp2 = new Date().toTimeString();

    // log time
    console.log(`${timestamp} - ${timestamp2}`);

Logs: 14:09:29 GMT-0500 (Eastern Standard Time) - 14:10:00 GMT-0500 (Eastern Standard Time)

I’ll shoot over the connection string shortly!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Text search with mongodb taking more than 30 seconds
I am using this simple query. When I use it without sort it runs right away but when I use sort it takes...
Read more >
MongoDB query with 300k documents takes more than 30 ...
MongoDB query with 300k documents takes more than 30 seconds ; 2. try to not to fetch all the data at once, use...
Read more >
Handling Slow Queries In MongoDB Pt. 1 - Rockset
We can also use the following command to list all the operations taking longer than a certain amount of time (in this case,...
Read more >
Let's .explain() MongoDB Performance | Twitch Live Coding
Query performance can either be a constant headache or the unsung hero of any application. A well-tuned database will save you time, ...
Read more >
Why MySQL Could Be Slow With Large Tables? - Percona
The table contains 36 million rows (Data size 5GB, Index size 4GB). I run the following query, which takes 93 seconds ! SELECT...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found