mongodb - Get all dynamic fields of a groovy class -
in application need use dynamic fields of class. object persisted mongodb (also dynamically) json request:
object obj = new object() def objectdata = request.json.object for(item in objectdata) { obj[item.key] = item.value } obj.save(flush: true)
however, when trying objct mongo, way:
list<object> objects = object.list() def objlist = new arraylist(); def filtered = ['class', 'active', 'metaclass', 'version'] for(obj in objects) { objlist.add(obj.properties) }
i getting this:
"objects" : [ { "dbo" : { "_id" : "531afe54300426462e60c1ce", "key2" : "val2", "key3" : "hello", "version" : 1, "key1" : "val1" } }, ...
of coarse can take "dbo" of every object, , filter don't need manually, looks wrong. right way properties of object including dynamic ones?
definition of object class:
package com.iibs.mongo class object { string id static mapwith = "mongo" static constraints = { } }
thanks,
Comments
Post a Comment