Quantcast

MongoDB - Can not get Dynamic Attributes after a findAll in a collection

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

MongoDB - Can not get Dynamic Attributes after a findAll in a collection

illyad
I have this domain model...

import org.bson.types.ObjectId

class Foo {
        ObjectId id
        boolean isNew
}


In a grails console I tried this

def foos = Foo.createCriteria().list(){
    eq('isNew', true)
}

println "................................"
println foos[0]['data'] // ok!
println "................................."

//Must have more than 1 result
//data has been addded Dinaymically
def m2 = foos.findAll{it['data']?.date && !it['data']?.name}


//The filter works ok, but the dynamic attribute just "disappears".....even if i do this
println "................................"
println foos[0]['data'] // null!
println "................................."

m2.each{it, i->
println it['data'] // always null if there are more than 1 record, only the last record has the data attribute
}



Does anybody knows why?, or what am i doing wrong.....

thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: MongoDB - Can not get Dynamic Attributes after a findAll in a collection

illyad
Ok, Doing more tests, workarounds, etc.....

def mongo = ctx.getBean('mongo')

def db = mongo.getDB('mongotest')
def fooRaw = db.foo.find(["isNew":true, "data.date" : [$exists:true]])

def m  = fooRaw .collect{Foo.get(it._id)}

m.each{
    println it['data'] //Always null
}
-------------------------------------

Foo.createCriteria().list{
    eq('isNew', true)
}.each{
    println it['data'] //but this works!!
}

...................................................

So at the end I think I will filter my collection this way


Foo.createCriteria().list{
    eq('isNew', true)
}.each{
    if(it['data'].date){
       println it['data'] //but this works!!
       ...............//logic and stuff........
    }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: MongoDB - Can not get Dynamic Attributes after a findAll in a collection

Ford Guo
I have the same problem,it's mongodb plugin bug?

-Ford
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: MongoDB - Can not get Dynamic Attributes after a findAll in a collection

Ford Guo
Loading...