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

0

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: 6 years 4 months ago

2 Answers:

1

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
988
Joined: Sep 7 2011 - 6:15pm
Last seen: 6 years 4 months 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 - 6 years 4 months ago
0

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: 6 years 4 months ago
Feedback
randomness