prisma连接MongoDB

Posted petewell

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了prisma连接MongoDB相关的知识,希望对你有一定的参考价值。

安装prisma

1
npm i -g prisma
1
prisma init db  //初始化prima

选择数据库

Set up a new Prisma server or deploy to an existing server? (Use arrow keys)
Set up a new Prisma server for local development (based on docker-compose):

  • ? Use existing database Connect to existing database // 连接本地数据库
  • Create new database Set up a local database using Docker // 新建数据库

Or deploy to an existing Prisma server:

  • Demo server + mysql database Free development environment hosted in Prisma Cloud //云数据库
  • Use other server Manually provide endpoint of a running Prisma server //云数据库

选择数据库类型

What kind of database do you want to deploy to? (Use arrow keys)

  • ? MySQL MySQL compliant databases like MySQL or MariaDB
  • PostgreSQL PostgreSQL database
  • MongoDB Mongo Database

? Set up a new Prisma server or deploy to an existing server? Use existing database ? What kind of database do you want to deploy to? MongoDB
? Enter MongoDB connection string mongodb://localhost:27017 ? Please select the schema you want to introspect yourdbname
*? Select the programming language for the generated Prisma client Don’t generate

输入连接字符

? Enter MongoDB connection string

1
mongodb://localhost:27017

初始化完成

Created 3 new files:
prisma.yml Prisma service definition
datamodel.prisma GraphQL SDL-based datamodel (foundation for database)
docker-compose.yml Docker configuration file

删除 schema: xxxxx 这行

Next steps:

  1. Open folder: cd db
  2. Start your Prisma server: docker-compose up -d
  3. Deploy your Prisma service: prisma deploy
  4. Read more about Prisma server:

prisma deploy
Creating stage default for service default ?
Deploying service default to stage default to server local 1.4s

Changes:

User (Type)

  • Created type User
  • Created field id of type ID!
  • Created field name of type String!

Applying changes 1.2s

Your Prisma endpoint is live:

HTTP: http://localhost:4466
WS: ws://localhost:4466

You can view & edit your data here:

Prisma Admin: http://localhost:4466/_admin

原文:大专栏  prisma连接MongoDB


以上是关于prisma连接MongoDB的主要内容,如果未能解决你的问题,请参考以下文章

prisma连接MongoDB

Prisma 绑定无法连接到 prisma 服务器。请求 http://localhost:4466/ 失败,原因:连接 ECONNREFUSED 127.0.0.1:4466

使用嵌套连接创建的 prisma 抛出错误

Nexus-prisma:排序嵌套连接

如何在 docker 容器中连接 graphql 和 prisma?

无法在 Prisma 中创建多个连接查询?