mongodbgrailsgrails-ormgrails-3.1gorm-mongodb

Grails 3.1 - Can't find codec for domain class


I am not able to convert domain class into Basic DB object. Below is my code:

def update_val    
class_object.class.withNewSession { MongoCodecSession m ->
             update_val = m.pendingUpdates.find {
                it.key.name == d.class.getName()
            }.value[0]nativeEntry.regions[0]."${instance.getDbKey()}"[0]
            }

On below findOneAndUpdate function, I am getting error: "Can't find a codec for class class.domain". updateVal is returning as Domain Class object.

ClassName.class.findOneAndUpdate(new BasicDBObject(findVal), new BasicDBObject(updateval))

I am converting it from Grails 3.0 to Grails 3.1, here nativeEntry is returning as a domain class while in previous version, nativeEntry is returning as BasicDBObject. Any solution? I am using Grails 3.1 with gorm 5.0 and mongodb 3.4


Solution

  • I have resolved it. Add below solution to Application.yml

    grails:
    mongodb:
       engine: mapping
    

    It will convert MongoCodecSession to the previous MongoSession. As in codecs, objects are no longer converted first to MongoDB Document objects and then to Groovy objects, instead the driver reads Groovy objects directly from the JSON stream at the driver level, which is far more efficient than the previous MongoSession.