First off all you could find out some plugins https://grails.org/plugins/search?q=mongo

But if you need you could use another method:

1. Edit BuildConfig.groovy
add string like this: compile ‘org.mongodb:mongo-java-driver:3.0.3’ to dependencies section

dependencies {
        //...
	compile 'org.mongodb:mongo-java-driver:3.0.3'
    }

2. Edit Config.groovy

mongodb.uri = "mongodb://username:password@your.mongodb.server/yourDataBaseName"
mongodb.database = "yourDataBaseName"

3. Add to resources.groovy

beans = {
	mongoClientURI(MongoClientURI) { bean ->
		bean.constructorArgs = [grailsApplication.config.mongodb.uri.toString()]
	}
	mongoClient(MongoClient) { bean ->
		bean.constructorArgs = [ref(mongoClientURI)]
		bean.destroyMethod = 'close'
	}
	mongoDb(mongoClient: 'getDB') { bean ->
		bean.constructorArgs = [grailsApplication.config.mongodb.database.toString()]
	}
}

4. Add to any controller (in my case MyController)

package mypackage

import com.mongodb.DB

class MyController {

	DB mongoDb

	def users() {

		def collection = mongoDb.getCollection('myCollection')

		collection.insert(new BasicDBObject(['name':'Piter']))
		
		def users = collection.find(new BasicDBObject(['name':'Piter'])).toArray()
		
		render (contentType: 'application/json', text: JSON.serialize(users))
	}

	def user() {

		def userId = params.userId
		
		def collection = mongoDb.getCollection('myCollection')
		
		def user = collection.findOne(new BasicDBObject(['_id': new ObjectId(userId)]))
		
		render (contentType: 'application/json', text: JSON.serialize(user))
	}

}

Для правильной сортировки строк на украинском языке или любом другом, необходимо явно указывать локаль Locale. Для решения данной проблемы используем класс пакета java.text – Collator.

ArrayList<String> countries = new ArrayList<String>();
countries.add("Єгипет");
countries.add("Туреччина");		
countries.add("Ісландія");		
countries.add("Аргентина");
		

System.out.println("Before sort:");
		
System.out.println(countries);
		

System.out.println("After regular sort:");
		
Collections.sort(countries);
		
System.out.println(countries);
		

Locale ukrainian = new Locale("uk", "UA");
		
Collator ukrainianCollator = Collator.getInstance(ukrainian);

Collections.sort(countries, ukrainianCollator);


System.out.println("After locale sort:");

System.out.println(countries);

Results

Before sort:
[Єгипет, Туреччина, Ісландія, Аргентина]
After regular sort:
[Єгипет, Ісландія, Аргентина, Туреччина]
After locale sort:
[Аргентина, Єгипет, Ісландія, Туреччина]

I have some view (“basicView.gsp”) and want to pass other view content (“_someTemplate.gsp”) to this view to javascript variable (“template”).

basicView.gsp:

<html>
<head>
...
</head>
<body>
...
<script>
var template = '${raw(include(view:"myTemplates/_someTemplate.gsp").replaceAll('\n',''))}';
</script>
</body>
</html>

_someTemplate.gsp:

<div>
<h1>Some header</h1>
<p>Lorem ipsum dolor sit...</p>
</div>

Resulted html:

<html>
<head>
...
</head>
<body>
...
<script>
var template = '<div><h1>Some header</h1><p>Lorem ipsum dolor sit...</p></div>';
</script>
</body>
</html>