2 Quickstart - Reference Documentation
Authors: Juri Kuehn
Version: 0.8.0
2 Quickstart
Here you will find a step by step guide to set up a test project that uses the mongodb-morphia plugin to manipulate domain classes in GrailsCreating a test project that uses mongodb-morphia
We are going to create a new Grails application that has only one domain class: Car. Using the generate-all command we will generate the controllers and views necessary to manipulate instances of that domain.Let's start off, create a new Grails project and install the mongodb-morphia plugin:> grails create-app MongoGrailsQuickstart > cd MongoGrailsQuickstart > grails install-plugin mongodb-morphia
> grails create-mongodb-class Car
mongodb { host = '192.168.1.36' // adjust this according to your settings port = 27017 databaseName = 'test' username = 'user' // database user and password, if server requires authentication password = 's3cret' }
mongodb { replicaSet = [ "localhost:27017", "localhost:27018"] databaseName = 'test' options = new MongoOptions(readPreference: ReadPreference.nearest()) // optional: configure MongoOptions here }
package mongograilsquickstartclass Car { String name String brand int ps // horsepower Date buildDate Date dateCreated // autoset by plugin Date lastUpdated // autoset by plugin static constraints = { brand nullable:true ps min: 30, max: 1001 } }
> grails generate-all mongograilsquickstart.Car > grails run-app