Take the 2-minute tour ×

Using mongodb in grails i am trying to get a hold of the database from a service in the same fashion as when connecting to it from a controller.


static mongo
    def db = mongo.getDB("dbone")

this does not seem to work. Is there a way to get a hold of the database from within a service in some other fasion?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You're using a 'static' variable which is incorrect. Try 'def mongo'

share|improve this answer
wow, be happy, you have been answered by Mr Grails :) –  fixitagain Jan 24 '12 at 13:18
this did take care of the problem! However i am having the problem that the service is continuously establishing new connections to the database for each new entry, is this the mongodb way or is there a way to "solv" this ? –  dunn less Jan 27 '12 at 10:09
add comment

Your Answer


