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

Multi hostname MongoDB connection string is not supported by Prisma Client #11873

Closed
Tracked by #8788
janpio opened this issue Feb 17, 2022 · 1 comment · Fixed by prisma/prisma-engines#2702
Closed
Tracked by #8788
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. topic: connection-url topic: mongodb
Milestone

Comments

@janpio
Copy link
Member

janpio commented Feb 17, 2022

MongoDB has a specific connection string format for replica set / sharded setups which lists the hosts explicitly: mongodb://user:password@my-shard-00.atlas.mongodb.net:27017,my-shard-01.atlas.mongodb.net:27017,my-shard-02.atlas.mongodb.net:27017/database?ssl=true&replicaSet=atlas-xxxxx-shard-0&authSource=admin&retryWrites=true

This is part of the MongoDB specification:

mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]

(via Standard Connection String Format)

(The listing of the individual hosts can be avoided by using the "DNS Seed List Connection Format", which uses mongodb+srv:// instead and then executes some logic to get the individual hosts)

Currently you can not use Prisma with this format.

Preproduction

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

datasource db {
  provider = "mongodb"
  url      = "mongodb://user:password@my-shard-00.atlas.mongodb.net:27017,my-shard-01.atlas.mongodb.net:27017,my-shard-02.atlas.mongodb.net:27017/database?ssl=true&replicaSet=atlas-xxxxx-shard-0&authSource=admin&retryWrites=true"
}

model User {
  id    String  @id @default(auto()) @map("_id") @db.ObjectId
  email String  @unique
}

This from DEBUG="*" npx prisma db pull CLI

❯ DEBUG="*" npx prisma db pull
[...]
Introspecting based on datasource defined in prisma/schema.prisma …
  prisma:introspectionEngine:rpc starting introspection engine with binary: /Users/j42/Dev/repro/11684/node_modules/@prisma/engines/introspection-engine-darwin +0ms
  prisma:introspectionEngine:rpc SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"introspect","params":[{"schema":"generator client {\n  provider        = \"prisma-client-js\"\n  previewFeatures = [\"mongoDb\"]\n}\n\ndatasource db {\n  provider = \"mongodb\"\n  url      = \"mongodb://user:password@my-shard-00.atlas.mongodb.net:27017,my-shard-01.atlas.mongodb.net:27017,my-shard-02.atlas.mongodb.net:27017/database?ssl=true&replicaSet=atlas-xxxxx-shard-0&authSource=admin&retryWrites=true\"\n}\n"}]} +7ms
  prisma:introspectionEngine:rpc {
  prisma:introspectionEngine:rpc   jsonrpc: '2.0',
  prisma:introspectionEngine:rpc   error: {
  prisma:introspectionEngine:rpc     code: 4466,
  prisma:introspectionEngine:rpc     message: 'An error happened. Check the data field for details.',
  prisma:introspectionEngine:rpc     data: {
  prisma:introspectionEngine:rpc       is_panic: false,
  prisma:introspectionEngine:rpc       message: 'invalid port number in database URL',
  prisma:introspectionEngine:rpc       backtrace: null
  prisma:introspectionEngine:rpc     }
  prisma:introspectionEngine:rpc   },
  prisma:introspectionEngine:rpc   id: 1
  prisma:introspectionEngine:rpc } +6ms

Error: Error: invalid port number in database URL

    at Object[...]

and for the client

[...]
  prisma:client:libraryEngine sending request, this.libraryStarted: false +29ms
  prisma:client:libraryEngine Searching for Query Engine Library in /Users/j42/Dev/repro/11684/node_modules/.prisma/client +1ms
  prisma:client:libraryEngine loadEngine using /Users/j42/Dev/repro/11684/node_modules/.prisma/client/libquery_engine-darwin.dylib.node +0ms
  prisma:client:libraryEngine library starting +12ms
  prisma:client:fetcher Error: The provided database string is invalid. Unable to parse URL. in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.
  prisma:client:fetcher     at /Users/j42/Dev/repro/11684/node_modu
[...]
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. topic: connection-url topic: mongodb labels Feb 17, 2022
@janpio
Copy link
Member Author

janpio commented Feb 17, 2022

The current error message is probably caused by us using an URL library to check the connection string for validity: https://github.com/prisma/prisma-engines/blob/b70a888e76ca5f3bd704f64afd8d03745a5c9205/query-engine/connectors/mongodb-query-connector/src/interface/mod.rs#L32-L37

@janpio janpio added this to the 3.10.0 milestone Feb 17, 2022
@matthewmueller matthewmueller added the team/schema Issue for team Schema. label Feb 18, 2022
@janpio janpio changed the title Sharded MongoDB connection string is not supported Sharded MongoDB connection string is not supported by Prisma Client Feb 18, 2022
@janpio janpio changed the title Sharded MongoDB connection string is not supported by Prisma Client Multi hostname MongoDB connection string is not supported by Prisma Client Mar 16, 2022
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/schema Issue for team Schema. topic: connection-url topic: mongodb
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants