Mongoose error
MongooseError: Operation users.find() buffering timed out after 10000ms
"MongooseError: Operation users.find() buffering timed out after 10000ms" means a query ran while the Mongoose connection was not ready, and the connection did not become ready within bufferTimeoutMS, which defaults to 10 seconds. Mongoose buffers commands until it connects, so the query waited and then gave up. It is a symptom: either connect() was never called on the connection the model uses, or it was called and is still failing. In a run with a server that never answers, the buffering error came at 10 seconds and the real error, Server selection timed out after 30000 ms, came at 30. Await the connection, catch its error and fix that one. Reproduced with mongoose 9.11.4 on 2026-10-31.
How do I see the real error behind it?
The Mongoose docs say to handle initial connection errors with .catch() or try/catch, and that serverSelectionTimeoutMS is 30000 by default. On 2026-10-31 I started mongoose.connect() against a local server that accepts connections and never answers, without awaiting it, then ran a query. The query failed at 10005 ms with the buffering error, and the pending connect() rejected at 30006 ms. A call that never reached mongoose.connect() gave the same buffering error and nothing after it, which is why a missing call is worth ruling out first.
MongooseError: Operation users.find() buffering timed out after 10000ms (10 s, the query)
MongooseServerSelectionError: Server selection timed out after 30000 ms (30 s, connect itself)How do I reuse the connection across Vercel invocations?
Mongoose's Next.js page points Vercel Serverless Function users to its AWS Lambda page. That page keeps the connection in a module-scope variable, awaits it after assigning it, so parallel calls do not open extra connections, and sets serverSelectionTimeoutMS to 5000 so a failure shows up in seconds. The MongoDB driver docs say most applications need only one MongoClient, even across requests, because it is a pool. Opening a connection per request can hit the cluster's limit: Atlas lists 1500 connections per node on an M10 in the general class. Vercel's Functions reference says to call attachDatabasePool(client) right after creating a MongoClient, so idle connections close before the function suspends.
let conn = null;
export async function connect() {
if (conn == null) {
conn = mongoose.createConnection(process.env.MONGODB_URI, {
serverSelectionTimeoutMS: 5000,
});
// await after assigning, so parallel calls share one connection
await conn.asPromise();
}
return conn;
}Why does only one model buffer and time out?
A model is bound to the connection it was created on. The Mongoose FAQ gives two causes of this error: calling a model method without ever calling mongoose.connect(), and using db.model(...) where db is a connection that is not connected. If you use createConnection(), register the models with conn.model(), not mongoose.model(), and await that same connection. Mongoose does not support the Edge Runtime, so a route that runs there cannot use it.
Checklist
How to fix it, then check the fix
- 01Find every place the app opens a connection, and which one each model uses:
grep -rnE "mongoose\.connect|createConnection|\.model\(" --exclude-dir=node_modules --exclude-dir=.next . - 02Make each route that queries await one cached connection before it runs a query, as in the helper above, and register the models on that connection.
- 03Wrap the connect in try/catch and log err.name and err.message. That message is the real problem. For a server selection timeout, check the Atlas IP access list and the cluster state; for a parse error, check the value of MONGODB_URI.
- 04Set serverSelectionTimeoutMS to a few seconds so the real error appears quickly instead of after the 30 second default.
- 05Redeploy, because Vercel applies changed variables only to new deployments, then call the route. The fix holds when the log shows no buffering error and the response contains your data.
Related
Related guides
Sources
Official docs behind this checklist
- Mongoose, Schemas (bufferCommands, bufferTimeoutMS)
- Mongoose, Connections
- Mongoose, Using Mongoose with AWS Lambda
- Mongoose, Using Mongoose with Next.js
- Mongoose, FAQ (operation timed out)
- Mongoose, drivers/node-mongodb-native/collection.js
- MongoDB Node.js driver, MongoClient
- MongoDB Atlas, Service limits (connection limits)
- Vercel, @vercel/functions API reference (attachDatabasePool)
- Vercel, Environment variables
More Vercel errors · More MongoDB errors
Browse all launch guides · Read resources · How to make and check your next change
FAQ
FAQ for builders before launch
Can I just raise bufferTimeoutMS?
It only changes how long Mongoose buffers before it throws. If the connection is failing, a longer wait gets you the same failure later. Fix the connection error instead.
Should I set bufferCommands to false?
The Mongoose docs say that turning it off disables buffering, which Mongoose does by default until the driver connects. It stops queries from waiting, but it does not make the connection work, so the cause still needs fixing.
Does Mongoose work in the Edge runtime?
The Mongoose docs say it does not currently support the Edge Runtime. Run the route on the Node.js runtime.