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.

MongoDB: Missing `&ssl=true` leads to `Error: unexpected end of file` on multi hostname connection string

See original GitHub issue

I have a multi hostname connection string like mongodb://user:password@cluster0-shard-00-00.bsdflt.mongodb.net:27017,cluster0-shard-00-01.bsdflt.mongodb.net:27017,cluster0-shard-00-02.bsdflt.mongodb.net:27017/test?retryWrites=true&w=majority&authSource=admin. Using it with Prisma Client leads to this error message:

$ ts-node ./script.ts
PrismaClientInitializationError: 
Invalid `client.user.deleteMany()` invocation in
/home/runner/work/e2e-tests/e2e-tests/databases/mongodb-atlas-sharded/script.ts:7:21

   4 
   5 // A `main` function so that we can use async/await
   6 async function main() {
→  7   await client.user.deleteMany(
  Database error. error code: unknown, error message: Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: cluster0-shard-00-02.bu2lt.mongodb.net:27017, Type: Unknown, Error: unexpected end of file }, { Address: cluster0-shard-00-01.bu2lt.mongodb.net:27017, Type: Unknown, Error: unexpected end of file }, { Address: cluster0-shard-00-00.bu2lt.mongodb.net:27017, Type: Unknown, Error: unexpected end of file }, ] }
    at cb (/home/runner/work/e2e-tests/e2e-tests/databases/mongodb-atlas-sharded/node_modules/@prisma/client/runtime/index.js:39812:17) {
  clientVersion: '3.10.0-dev.71',
  errorCode: undefined
}
error Command failed with exit code 1.

Adding &ssl=true to the connection string makes the script succeed.

(I got this connection string by manually converting a mongodb+srv one to a normal mongodb one that lists the shards in the hostname with comma separation.)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Nov 28, 2022

Open a new issue for this please @moersoy, this one is explicitly for multi hostname connection strings. Thanks.

0reactions
moersoycommented, Nov 28, 2022

Invalid `prisma.account.upsert()` invocation:


Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawDatabaseError { code: "unknown", message: "unexpected end of file" } })

MONGO_DATABASE_URL="mongodb+srv://username:password@cluster.id.mongodb.net/hyperdrive?retryWrites=true&w=majority&ssl=true"

I’m getting this error even though there is only one hostname connection. This error usually appeared when the number of instant connections was high.

@prisma/client”: “4.5.0”, node:16-alpine, Google CloudRun

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection issue with mongoose db error for multiple host ...
I am trying to connect to a mongodb atlas free cluster. however the error tells me that connection string can not contain multiple...
Read more >
MongoClient or how to connect in a new and better way
The main difference is that the constructor is missing the database name from Db. Let's show a simple connection using open as a...
Read more >
mongo_client – Tools for connecting to MongoDB - PyMongo
The client object is thread-safe and has connection-pooling built in. If an operation fails because of a network error, ConnectionFailure is raised and...
Read more >
Mongoose v6.8.1: Connecting to MongoDB
See the mongodb connection string spec for more details. ... Replica Set Host Names; Multi-mongos support; Multiple connections; Connection Pools ...
Read more >
Connecting MongoDB To Ruby With Self-Signed SSL ...
First, find and copy your MongoDB connection string from the ... due to: Mongo::Error::SocketError EOFError: end of file reached (for ...
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