0

We're using mongodb in our grails 2.3.5 app without hibernate. When using projection in criteria with minimum two fields the result returned is a different as returned in hibernate criteria. For example:

List usersList = User.withCriteria {
    projections {
        id()                          // For mongodb
        //property("id")              // For hibernate
        property('name', 'fullName')
    }
    def now = new Date()
    between('joinDate', now-365, now)
    maxResults(2)
}

Considering two instances are returned matching above criteria:-

Result returned when using mongodb will be:

[[1, 2], ['XYZ', 'ABC']]

While returned result when using hibernate will be:

[[1, 'XYZ'], [2, 'ABC']]

I'm not sure if this is by implementation or this is a bug.

Thank You,

SA

saw303
  • 8,051
  • 7
  • 50
  • 90
Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121

1 Answers1

1

Which version of the MongoDB plugin? This was a bug in the past, but was fixed see

https://github.com/grails/grails-data-mapping/blob/master/grails-datastore-gorm-mongodb/src/test/groovy/org/grails/datastore/gorm/mongo/ProjectionsSpec.groovy#L38

which verifies the behavior is correct

The issue https://jira.grails.org/browse/GPMONGODB-294 was fixed in version 3.0.0 of the plugin

Graeme Rocher
  • 7,985
  • 2
  • 26
  • 37
  • Okay We're on grails-mongodb 2.0.1 version. I didn't notice that this is already fixed. Will upgrade to latest version. Thank You Graeme. – Shashank Agrawal May 13 '14 at 12:52