medz / prisma-dart

Prisma Client Dart is an auto-generated type-safe ORM. It uses Prisma Engine as the data access layer and is as consistent as possible with the Prisma Client JS/TS APIs.
https://prisma.pub
BSD 3-Clause "New" or "Revised" License
453 stars 31 forks source link

Connecting to Atlas MongoDB #62

Closed boosey closed 1 year ago

boosey commented 1 year ago

I have been struggling for 3 days to connect to either local or Atlas Mongo. I continue to receive a Connection Refused with no error code. I have tried every variation of the connection string including adding authSource=admin. The connection string works fine in mongosh and Compass.

Here is my current connection string: mongodb+srv://xxxxxx:yyyyyy@xxxcluster.ki1jpzv.mongodb.net/cbm?retryWrites=true&w=majority&ssl=true&authSource=admin

This is the error I get back: PrismaClientInitializationError: message: Failed to start the query engine: Connection refused errorCode: null clientVersion: 2.4.3

medz commented 1 year ago

@boosey https://www.prisma.io/docs/concepts/database-connectors/mongodb#connection-details

medz commented 1 year ago

@boosey protocol is mongodb:// and your input mongodb+srv is invalid

medz commented 1 year ago

@boosey Maybe related to OpenSSL, I will create a similar scenario to test the MongoDB connection for further testing.

sunlimiter commented 1 year ago

@medz I have a similar problem mongodb

mongodb://xxxx:xxxx@localhost:27017/?authSource=xxxxx&ssl=false
PrismaClientKnownRequestError(
  message: Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: RawDatabaseError { code: "unknown", message: "Command failed (Unauthorized): command find requires authentication)" } }),
  code: UNKNOWN,
  meta: null,
  clientVersion: 2.4.3,
)
medz commented 1 year ago

@sunlimiter 我没使用 mongdb,我感觉得等到我周末空了才能测试 mongdb😂,要修复这个问题得与 Prisma JS/TS 客户端进行连接数据的对比才能修复。这几天公司加班严重,工作日没啥时间处理这个问题。

extrordinaire commented 1 year ago

I'll take a look! WML 😁

sunlimiter commented 1 year ago

:open_mouth: @medz 我把文档看了几遍,发现是调用了生产环境的配置文件,我只改了prisma/development.dart下面的配置,lib/prisma_configurator.dart里面默认生成的,导致运行的时候连接失败 没发现哪里设置开发模式,生产模式,如果可以的话,建一个mongo的demo最好啦

medz commented 1 year ago

😮 @medz 我把文档看了几遍,发现是调用了生产环境的配置文件,我只改了prisma/development.dart下面的配置,lib/prisma_configurator.dart里面默认生成的,导致运行的时候连接失败 没发现哪里设置开发模式,生产模式,如果可以的话,建一个mongo的demo最好啦

我没找到 Dart 项目比较好的配置方式,dotenv 问题也很大。我常用方法是删除 prisma_configurator.dart