Search code examples
mongodbgrailsmongodb-atlas

Does anyone know how to connect grails app to mongoDB cloud database?


I created a database in MongoDB atlas and I want to create a Grails app that will connect to that database, and I have no idea how to do it. Here's what I tried in "application.yml" file, but it doesn't work.

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

Thanks


Solution

  • I tried this way and it worked!

    environments:
            development:
                grails:
                    mongodb:
                        url: "mongodb+srv://x:[email protected]/tpt?retryWrites=true&w=majority"
            test:
                development:
                    grails:
                        mongodb:
                            url: "mongodb+srv://x:[email protected]/tpt?retryWrites=true&w=majority"
            production:
                development:
                    grails:
                        mongodb:
                            url: "mongodb+srv://x:[email protected]/tpt?retryWrites=true&w=majority"