有谁知道如何将 grails 应用程序连接到 mongoDB 云数据库?

时间:2021-06-22 19:49:27

标签: mongodb grails mongodb-atlas

我在 MongoDB atlas 中创建了一个数据库,我想创建一个连接到该数据库的 Grails 应用程序,但我不知道该怎么做。这是我在“application.yml”文件中尝试过的,但不起作用。

environments:
    development:
        grails:
            mongodb:
                host: "clustertpt.nfycx.mongodb.net"
                port: 27017
                username: "x"
                password: "x"
                databaseName: "tpt"
    production:
        grails:
            mongodb:
                host: "clustertpt.nfycx.mongodb.net"
                port: 27017
                username: "x"
                password: "x"
                databaseName: "tpt

谢谢

1 个答案:

答案 0 :(得分:0)

我试过这种方法,它奏效了!

environments:
        development:
            grails:
                mongodb:
                    url: "mongodb+srv://x:x@clustertpt.nfycx.mongodb.net/tpt?retryWrites=true&w=majority"
        test:
            development:
                grails:
                    mongodb:
                        url: "mongodb+srv://x:x@clustertpt.nfycx.mongodb.net/tpt?retryWrites=true&w=majority"
        production:
            development:
                grails:
                    mongodb:
                        url: "mongodb+srv://x:x@clustertpt.nfycx.mongodb.net/tpt?retryWrites=true&w=majority"