Skip to content

Instantly share code, notes, and snippets.

@graemerocher
Created November 25, 2011 14:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save graemerocher/1393603 to your computer and use it in GitHub Desktop.
Save graemerocher/1393603 to your computer and use it in GitHub Desktop.
Using GORM from MongoDB from a Groovy Script
@GrabResolver(name='grails-core', root='http://repo.grails.org/grails/core')
@Grab(group='org.grails', module='grails-datastore-gorm-mongo', version='1.0.0.BUILD-SNAPSHOT')
@Grab(group='org.slf4j', module='slf4j-simple', version='1.6.1')
import grails.persistence.*
import org.grails.datastore.gorm.mongo.config.*
MongoDatastoreConfigurer.configure("myDatabase", Book)
Book.withSession {
new Book(title:"The Stand").save(flush:true)
Book.list().each {
println it.title
}
}
@Entity
class Book {
String title
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment