how do you do a select distinct .. in jaspersoft mongodb query language?

How do you select distinct values from a field  in jaspersoft mongodb query language?

if mongodb you'd write :

db.collectionName.distinct('fieldname')

 

in sql , you'd write

select distinct field1 from table1

 

So how do you that in jaspersoft mongodb query language???

 

 

aidan.geraghty's picture
Joined: Feb 21 2013 - 6:09am
Last seen: 10 years 1 month ago

2 Answers:

Aidan,

You can achieve the same behavior using a set of aggregation expressions.

Here is an example of the MongoDbQuery

{

  runCommand : {

    aggregate : "test",

    pipeline: [

     {

       $sort : { name : 1 }

     },

     {

      $group : { _id : "$name" }

     }

     ]

  }

}

Where:

  • aggregate: Is the collection you want to use
  • pipeline: Defines a set of aggregation expressions to be applied

You can find more examples of the MongoDbQuery language here: http://community.jaspersoft.com/wiki/jaspersoft-mongodb-query-language

Also you can find the list of aggregations that MongoDb supports http://docs.mongodb.org/manual/reference/aggregation/

eddiaz's picture
2256
Joined: Sep 7 2011 - 6:15pm
Last seen: 10 years 1 month ago

I suppose "distinctQuery" could be added as an enhancement to the MongoDB query language just like "findQuery". But using aggregation is much more easily extendable (e.g. to add sums or counts to the groups). Aiden, does this answer work well for you?

mdahlman - 10 years 1 month ago

By using the above sample syntax I was able to do a 'select distinct'.

Thanks

 

aidan.geraghty's picture
Joined: Feb 21 2013 - 6:09am
Last seen: 10 years 1 month ago
Feedback
randomness