how to avoid having mongodb as default datasource when working with multiple datasources in grails 3

161 views Asked by At

I have my application.groovy set up as :

environments {
    development {
        mongo {
            host = 'localhost'
            port = 27107
            username = dbusername
            password = dbpassword
            databaseName = dbname
        }
        dataSources {
            dataSource {
                pooled = true
                jmxExport = true
                driverClassName = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
                dbCreate = ''
                username = dbusername
                password = dbpassword
                url = 'jdbc:sqlserver://${dbserver}:${dbport};databaseName=${dbname}'
            }
        }
    }
}

But now it seems like all of my domain's data source points to the mongodb so I can no longer query my domains that are linked to mssql db. How can I avoid this?

Secondary question though not that important: The mongodb plugin documentation says to put the connection config within the environment->development - I wonder why we can't put it within dataSources so its much neater(in domain I can just point to the dataSource). I tried to move the config within dataSources and it didn't work!

In the debugger if I run MyDomain.list() and I get

result = {MongoQuery$MongoResultList@12334} size = 0

Any help will be much appreciated, thanks in advance Dee

1

There are 1 answers

0
Deewendra Shrestha On

I was trying to use the "mongodb" plugin, I am not sur eif its supported in grails 3. I have things working with gmongo. I added these two dependencies in by build.gradle :

compile "org.mongodb:mongo-java-driver:3.0.2"
compile "com.gmongo:gmongo:1.5"

and removed the mongo config.

environments {
    development {
        mongo {
            host = 'localhost'
            port = 27107
            username = dbusername
            password = dbpassword
            databaseName = dbname
        }
      ....
   }
}

gmongo seems to take default database credentials. This is how I created db instance to work off of it:

 def mongo = new GMongo()
 def db = mongo.getDB("dnName")

Hope this helps someone facing similar problem.