mongodbgrailsgorm-mongodb

Grails MongoDB plugin: Values in v:2 index key pattern cannot be of type bool


I have a Grails 3.3.2 application with GORM 6.1.8 and am using the mongodDB grails plugin 6.1.4.

When trying to connect to a 3.4 MongoDB instance, the application makes an error at startup:

Caused by: com.mongodb.MongoCommandException: Command failed with error 67: 'Values in v:2 index key pattern cannot be of type bool. Only numbers > 0, numbers < 0, and strings are allowed.' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "Values in v:2 index key pattern cannot be of type bool. Only numbers > 0, numbers < 0, and strings are allowed.", "code" : 67, "codeName" : "CannotCreateIndex" }

Using the debugger, I could find the domain whose index creation failed:

class MyClass{
    Long field1
    String field2
    Long index

    static mapWith = "mongo"

    static mapping = {
        database "databasename"
    }

    static constraints = {
        field1 nullable: true
        field2 nullable: true
    }
}

It is embedded in another domain.

What's wrong with this domain class? I also tried to connect to a 3.6 and 4.0 MonogoDB instance, with the same error.


Solution

  • Found out empirically that the Long 'index' attribute of the domain class causes the error. Removing the attribute from the domain fixes the issue.