black sensei
black sensei

Reputation: 6677

Completely lost on getting grails 3.X.X work with mongob

I have been struggling to get grails 3.1.7 to connect to local mongo db. I have implemented various suggestion via main documentation. I have gone through some post on stackoverflow by Alex M and Armarnath

My build.gradle looks like the following:

// ...
compile 'org.grails.plugins:mongodb'
compile "org.mongodb:mongodb-driver:3.0.2"
runtime 'org.springframework.data:spring-data-mongodb:1.8.1.RELEASE'
//compile 'org.mongodb:mongo-java-driver'
//compile("org.grails:gorm-mongodb-spring-boot:5.0.6.RELEASE")

//compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
//compile "org.hibernate:hibernate-ehcache"
// ...

My application.yml is looking like the snippet below:

//...
 environments:
  development:
    dataSource:
      grails:
        mongodb:
          connectionString: "mongodb://localhost:27017/project-db"
#        dbCreate: create-drop
#        url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
    dataSource:
#        dbCreate: update
#        url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
production:
    dataSource:
#        dbCreate: update
#         url: jdbc:h2:./prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
#        properties:
#            jmxEnabled: true

//...

Here is a sample model:

class FlowInfo {

    int posIndex
    String tagName
    Boolean isEnabled
    String name
    static mapWith="mongo"
    static constraints = {
        posIndex unique: true
    }


}

It looks like I am still getting data pulled from the first initial in memory database created probably at the first run of the seeding from the BootStrap.groovy. Is there a way to make this work. looks like different strategies worked for different people.

thanks for reading this.

Upvotes: 0

Views: 152

Answers (1)

Manali Khanna
Manali Khanna

Reputation: 101

I tried it with following configuration in application.yml that worked for me:

environments:
    development:
        grails:
            mongodb:
                connectionString: mongodb://localhost:27017/database-name

You might remove dataSource and try once.

Upvotes: 1

Related Questions