SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

Aggregation Functionality bug: filter #102

Closed vinodprathipati closed 8 years ago

vinodprathipati commented 8 years ago

We receive class cast exception during the following aggregation.

db.asset.aggregate( {$match:{"cntry_of_iss_cd" : "US","cpn_class_cd":"FIX ","debt_type_cd":"BND","put_terms_fl" : "n","ds_type_cd":"CORP"}} , {$project:{asset_id:1, cntry_of_iss_cd:1, cpn_class_cd:1, debt_type_cd:1, put_terms_fl:1, ds_type_cd:1,amt_outsd_hist: {$filter: { input:"$amt_outsd_hist", as : "item", cond: { $and: [{$lte:["$$item.amt_out_dt",ISODate("2003-12-18T04:00:00Z")]},{$gt:["$$item.amt_out_end_dt",ISODate("2003-12-18T04:00:00Z")]}]}} }}} )

I noticed the bug at AbstractAggregationOperation class during bindAggregationVariables.

vinodprathipati commented 8 years ago

Basically, It is failing for any operation which takes string parameters.

Example : "_$min " :["$rating_hist.MDY.rank","$rating_hist.S&P.rank"]

ujibang commented 8 years ago

Hi @vinodprathipati,

bug reproduced, will fix soon...

Thanks for reporting it.

ujibang commented 8 years ago

Hi @vinodprathipati

fixed in master and 1.1.x branches.

before releasing a new version I would ask you to try it. will you help?

$ git clone https://github.com/SoftInstigate/restheart.git
$ git checkout 1.1.x
$ mvn package

and use restheart.jar you'll find in target dir. thanks

vinodprathipati commented 8 years ago

I will test this and let you know soon. Thanks

vinodprathipati commented 8 years ago

Hi ,

I tested this. It is not throwing exception. But there is different problem...

Let's take this example :

1) I am doing an aggregation and i am projecting the minimum of few nested fields.

{"_$project":{"id":0, minRank: { "$min":["$rating_hist::MDY::rank","$rating_hist::S&P::rank"]} }}

the nested fields are at 2 levels down. The values are not coming up. The expressions are not getting resolved if the nested fields are more than 1 level.

Thanks, Vinod

ujibang commented 8 years ago

the _$ and :: needs to be used only in objects keys.

can you try

{"$project":{"_id":0, minRank: { "$min":["$rating_hist.MDY.rank","$rating_hist.S&P.rank"]} }}
vinodprathipati commented 8 years ago

Hmm. It's my bad.. Yes.. we can close this bug.

I will test more.