How can i find Mongodb connection string for Prisma project? - mongodb

I want to create a project using Prisma and i want to connect it to my local Mongodb database but i cant find the connection string it should be like this : http://user1:myPassword#localhost:27017/admin
If anyone knows how can i find my user and password.

You have to create the user in your mongodb server.

If you are using Prisma CLI, you can configure your database connection in the file docker-compose.yml,
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.34
restart: always
ports:
- '4466:4466'
environment:
PRISMA_CONFIG: |
port: 4466
databases:
default:
connector: mongo
uri: mongodb://http://user1:myPassword#localhost:27017/admin
database: mydb
Check this link for more info

Related

Mongo Express authentication failed with docker compose

I am trying to run mongodb and mongo express in two containers using docker-compose. It seems like the mongodb container works fine but the mongo express container keeps exiting with code 0.
The error I get is: Could not connect to database using connectionString: mongodb://rootuser:rootpass#mongodb:27017/"
mongo-express | (node:8) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongodb:27017] on first connect [MongoError: Authentication failed.
My docker-compose.yml looks like this:
version: "3.8"
services:
mongodb:
image: mongo
container_name: mongodb
ports:
- 27017:27017
volumes:
- data:/data
environment:
- MONGO_INITDB_ROOT_USERNAME=rootuser
- MONGO_INITDB_ROOT_PASSWORD=rootpass
mongo-express:
image: mongo-express
container_name: mongo-express
restart: always
ports:
- 8081:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=rootuser
- ME_CONFIG_MONGODB_ADMINPASSWORD=rootpass
- ME_CONFIG_MONGODB_SERVER=mongodb
volumes:
data: {}
networks:
default:
name: mongodb_network
In MongoDB you can create user accounts in any database you wish. For example, I can create a user account called 'JohnDoe' in database 'MyDatabase1' and another account called 'JohnDoe' in database 'MyDatabase2'. These are two different accounts. You specify the authorizing database in your database connection string. Because of this feature it can become confusing. As such it has become the standard, and recommended approach to create database users in a single database called 'admin'. By adding users to a single database it is easier to manage.
In this post, you did not identify/specify which database is your authorization database for the user 'rootuser' and the connection info does not seem to contain such a concept. I suspect your user is defined in a database but when you attempt to connect it is looking at the temp database and not finding the user.

Cannot get Prisma to work with an existing MySQL DB that has data on it

First of all we have a MySQL DB setup on Heroku that already has data on it. I'm trying to add the Prisma layer on top of our DB.
My docker-compose.yml:
version: "3"
services:
prisma:
image: prismagraphql/prisma:1.34
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
databases:
default:
connector: mysql
host:
database:
user: user
password:
rawAccess: true
port: '3306'
migrations: false
Prisma.yml
# The HTTP endpoint for Prisma API
endpoint: http://localhost:4466
# Points to the file that contains your datamodel
datamodel: datamodel.prisma
# Specifies language and location for the generated Prisma Client
generate:
- generator: javascript-client
output: ./generated/prisma-client/
I go through prisma init and it connects to the DB and sets up the datamodel as it should, from what it seems like.
After docker-compose up -d I run prisma deploy and it hits me with
Could not connect to server at http://localhost:4466. Please check if
your server is running.
I run systemctl status docker and the docker is running as it should.
I then run docker-compose logs and I get back this
Exception in thread "main" java.sql.SQLSyntaxErrorException:
(conn=10044859) Access denied for user 'user'#'%' to database 'prisma'
So from reading around does prisma need the DB user to have the privileges to create a new schema in the DB for its management purposes?
I have no clue where to go from here. If I'm doing something wrong here, the help would be much appreciated!
Btw: SSL is not active on the DB so there is no need for it to be true.

FluentMySQL migration fails when building with docker-compose but not when building from Xcode

I'm getting the following crash when using docker-compose with Vapor & FluentMySQL.
api_1 | [ INFO ] Migrating 'mysql' database (/app/.build/checkouts/fluent/Sources/Fluent/Migration/MigrationConfig.swift:69)
api_1 | Fatal error: Error raised at top level: NIO.ChannelError.connectFailed(NIO.NIOConnectionError(host: "db", port: 3309, dnsAError: nil, dnsAAAAError: nil, connectionErrors: [NIO.SingleConnectionFailure(target: [IPv4]db/172.27.0.2:3309, error: connection reset (error set): Connection refused (errno: 111))])): file /home/buildnode/jenkins/workspace/oss-swift-5.1-package-linux-ubuntu-18_04/swift/stdlib/public/core/ErrorType.swift, line 200
Migration fails when using:
migrations.add(model: Model.self, database: .mysql)
If I remove that so no Models are migrated the app builds without errors and I am able to access it at http://localhost/.
My docker-compose.yml looks like this:
version: "3.7"
services:
api:
image: vaporapiimage
ports:
- 80:8080
environment:
MYSQL_HOST: db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_DATABASE: dbname
SLEEP_LENGTH: 7
MYSQL_PORT: 3309
depends_on:
- db
db:
image: mysql:8.0.1
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: dbname
MYSQL_USER: user
MYSQL_PASSWORD: password
ports:
- "3309:3306"
It builds and runs as expected locally from Xcode (as in without Docker).
If the api service is commented out then the db service will run on its own and create the database on first run.
Any help would be greatly appreciated.
UPDATE:
Replacing the api with Adminer results in being able to access the db through Adminer in the browser. So the db service is accessible and it seems as if the issue is with Vapor/Fluent (or rather my use of them):
admin:
image: adminer
ports:
- 8080:8080
The problem was that I had mapped the port for db to 3309 so that it didn't conflict with the host MYSQL but had also set the ENV 'MYSQL_PORT' to 3309 when that should have been kept as the default 3306 because that was for communication between containers.

Prisma Creating New Database in MongoDB

I've got Prisma connected to my MongoDB but when I make any mutations, a new database is being created in MongoDB called default_default and data is being added there instead of the database I specified when going through the setup here
https://www.prisma.io/docs/get-started/01-setting-up-prisma-existing-database-JAVASCRIPT-a003/
I'd expect the data to be saved in the database specified in the docker-compose.yml file
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.23
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
databases:
default:
connector: mongo
uri: 'mongodb://host.docker.internal:27017/my-db-name'
Has anyone experienced something similar and found a solution?
Thanks
This you do in prisma.config by setting endpoint:
endpoint: http://localhost:4466/graphql/default
This will use database graphq_default

Specific database details in docker-compose.yml file?

The service I'm using gives you a command to create a docker-compose file. You can then run docker-compose up and choose to create a new database.
version: '3'
services:
prisma:
image: prismagraphql/prisma:1.8
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
databases:
default:
connector: mysql
host: mysql
port: 3306
user: root
password: prisma
migrations: true
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: prisma
volumes:
- mysql:/var/lib/mysql
volumes:
mysql:
This worked but now I need to set a second project with a new database. Even though I chose the option to set up a new database when I run my project I can see it's connecting to my old one:
prisma init
? Set up a new Prisma server or deploy to an existing server? Create new database
? What kind of database do you want to deploy to? MySQL
Created 3 new files:
prisma.yml Prisma service definition
datamodel.graphql GraphQL SDL-based datamodel (foundation for database)
docker-compose.yml Docker configuration file
Next steps:
1. Start your Prisma server: docker-compose up -d
2. Deploy your Prisma service: prisma deploy
3. Read more about Prisma server:
Is there something in my docker-compose.yml thats wrong? I belive default is the database name so I've tried the following but the same thing happens:
databases:
default2:
connector: mysql