apache / apache/grails-core

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

Open
#14,397 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-mongodb
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

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 embedded in another domain.

What's wrong with this domain class? I had the same results with a Mongo 3.6 and 4.0 instance ( I'm using the official mongoDB docker instances ).

PS: finally found it; the index attribute of the domain causes the error; removing it makes everything work again.

Contributor guide

Open the contributing guide

Research direction

The report points to MongoDB index creation during Grails application startup and shows a domain class containing a field named index. Start by reproducing the startup failure with the stated MongoDB versions and that domain definition. Done means the application starts successfully without the reported CannotCreateIndex error while preserving the domain's intended indexing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, mongodb
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.