Integrate MongoDB with Grails
This quickstart guide will help you to integrate your Grails application with MongoDB service on App42 PaaS.
Kontena – Kontena is a lightweight container that will run your apps and services in an isolated and secured manner. You can specify the power of the Kontena while setting up infra or creating services. One Kontena power specifies to 256 MB Memory and 128 MHz CPU.
Service – Services in the App42 PaaS are add-on components which are needed in an App. App42 PaaS supports multiple services like SQL databases, NoSQL databases and more.
To get going with App42 PaaS, below are few prerequisites that will allow you to use AppHQ – App42 PaaS Management Console as well as Command Line Client.
Once you have setup the Grails environment and created the MongoDB service, You need to configure the MongoDB credentials in your created Grails application.
// using grails grails { mongo { host = "service_vm_ip" port = service_port username = "username" password = "password" databaseName = "database_name" } } For further info visit ( http://blog.mongodb.org/post/18510469058/grails-in-the-land-of-mongodb, http://etcpe9.wordpress.com/2012/01/28/beginning-grails-2-0-with-mongodb ). // using mongo-java-driver String host = "service_vm_ip"; String username = "username"; String password = "password"; String dbName = "database_name"; int port = service_port; // eg, 23453 MongoClient mongoClient = new MongoClient(host, port); DB db = mongoClient.getDB(dbName); // com.mongodb.DB; boolean auth = db.authenticate(username, password.toCharArray()); if (!auth) { throw new Exception("Authentication Failed"); }
You can also use our Sample Apps and extend it to suit your needs. Here is the link to Grails-MongoDB Sample App
After doing all the modifications to your App, you need to update it on App42 PaaS to get the changes affected in your App running on App42 PaaS platform.
$ app42 update Enter App Name: testGrails 1: Binary 2: Source Choose Upload Type [Binary]: 2 Updating Application... OK Operation is in progress, Please wait...- App deployed successfully.