prisma 已经支持mongodb了,我们需要做的就是安装新版本的prisma cli,后然初始化项目使用

环境准备

  • 安装cli

npm install  -g prisma
  • 初始化一个mongodb 的项目
prisma init mongodb-demo
? 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? MongoDB
? Select the programming language for the generated Prisma client Prisma JavaScript Client Created 3 new files: prisma.yml Prisma service definition
datamodel.prisma GraphQL SDL-based datamodel (foundation for database)
docker-compose.yml Docker configuration file Next steps: 1. Open folder: cd mongodb-demo
2. Start your Prisma server: docker-compose up -d
3. Deploy your Prisma service: prisma deploy
4. Read more about Prisma server:
http://bit.ly/prisma-server-overview

启动&&测试

  • 启动

docker-compose up -d
  • deploy
prisma deploy
  • 查看graphql 信息
    prisma mongodb 试用-LMLPHP
  • 数据添加操作
    prisma mongodb 试用-LMLPHP
  • 数据查询操作
    prisma mongodb 试用-LMLPHP

说明

以上只是简单的操作,同时还支持数据订阅,还是很方便,只是官方文档就有点不是很好了

参考资料

https://www.prisma.io/docs/prisma-cli-and-configuration/prisma-yml-5cy7/
https://www.prisma.io/docs/1.32/prisma-server/database-connector-MONGO-jgfm/

 
 
 
 
05-16 12:58