سؤال

How do I create / or ensure that an index exists for my domain class using Grails 2.4RC1 / Mongo GORM Plugin and Mongo DB 2.6 in --auth mode: ?

Let's assume: 1) I have a valid user identified with appropriate roles in my Mongo Instance. 2) I am able to authenticate to that user using the connectionString configuration in DataSource.groovy 3) I define in the static mapping { lname index:true } for my Person domain class

I will get an error on startup indicating that my user doesn't have the authority to run the createIndex command. I do not get this error when mongo is not run in --auth mode

I have a work around, which I'll attach to this question, but I would think that it would work as documented.

هل كانت مفيدة؟

المحلول

You can address the mongo instance and use the low level api to manage your indices as shown below:

In your Bootstrap.groovy you can add:

def mongo

def init = { servletContext ->
   def db = mongo.getDB("yourdbname")
   db.person.ensureIndex([lname: 1, fname:1])
}

Not what I would consider the best solution, but it seems to work.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top