When I try to store a byte array as a field of a domain class in a grails application, The resulting entry in the mongo database is the object id of the byte array instead of the BinData object which I expected.
Example:
class SimpleDomainClass {
byte[] filed = ['d', 'w', 1, 5, 'r']
}
Results in the following in the Mongo DB:
{"field" : "[B@29edc561"}
I’d expect something more like:
{"field" : BinData(0,"blahblahblah")}
The mongo-java driver docs clearly state that this should be stored as a binary object and it is working for us on a similar project with similar configuration.
Does anyone have any idea what might be the issue here?
Library Versions:
- Grails 2.1.0
- plugins.mongodb=1.1.0.GA
- mongo-java-driver 2.10.1
You’re absolutely right, documentation says that it should work. There’s a bug GPMONGODB-265 in
1.1.0.GA mongodbplugin which produces arrays saving error.The same issue discussed: Grails – Mongo: storing images as byte array
However since you use
grails 2.1.0you have a change to downgrade mongo gorm plugin to version1.0.0.GA, arrays are saved correctly there.