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???
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/
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?