MongooseError - Operation `users.findOne()` buffering timed out after 10000ms
In my experience this happens when your database is not connected, Try checking out following things -
- Is you database connected and you are pointing to the same url from your code.
- check if your
mongoose.connect(...)
code is loading.
I faced this issue where I was running the node index.js
from my terminal and mongoose connect code was into different file. After requiring that mongoose code in index.js it was working again.
According to Documentation found in this link: https://mongoosejs.com/docs/connections.html#buffering
Mongoose lets you start using your models immediately, without waiting for mongoose to establish a connection to MongoDB.
That's because mongoose buffers model function calls internally. This buffering is convenient, but also a common source of confusion. Mongoose will not throw any errors by default if you use a model without connecting.
TL;DR:
Your model is being called before the connection is established. You need to use async/await with connect() or createConnection(); or use .then(), as these functions return promises now from Mongoose 5.
I had the same issue when using Mongoose 6. I connected to Mongoose in my index.js file the following way:
mongoose.connect(
process.env.MONGO_URL,
{ useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true },
() => {
console.log('Connected to MongoDB');
}
);
I found the following info for Mongoose 6 in their site:
useNewUrlParser, useUnifiedTopology, useFindAndModify, and useCreateIndex are no longer supported options. Mongoose 6 always behaves as if useNewUrlParser, useUnifiedTopology, and useCreateIndex are true, and useFindAndModify is false. Please remove these options from your code.
When I removed the useCreateIndex: true
option the issue was solved.