1) A direct query to the database looks like this:

db.getCollection('collection').distinct("body.uniq_value_id"); 

- we get all the unique uniq_value_id values.

2) Directly on Java there is such an implementation:

  List uniqlist = collection.distinct("body.uniq_value_id"); for (int i = 0; i < uniqlist.size(); i++) { System.out.println(varTextB.get(i)); } 

- here we will get all the unique values uniq_value_id IN uniq_value_id .

3) Then there is a request in the format:

 db.tracking.distinct("body.uniq_value_name", {"body.uniq_value_id":"some_id1"}); 
  • this query in turn will display all the unique values ​​of body.uniq_value_name for records where body.uniq_value_id will be some_id1 .

The question is how to use similar queries in Java? The question is relevant because the query syntax can be structurally complex, for example:

 db.collection.find({"body.uniq_value_name":"some_name1","body.uniq_other":{$in:[/active.*=.*yes/i]}}).pretty(); 
  • If you use spring-data then there are already a lot of answers ru.stackoverflow.com/questions/639348/… - alexandr gaiduchok
  • Thanks for the links, it was possible to implement through Jongo. - Aeroua
  • Jongo / Aggregation: List<String> result = collection.distinct("body.uniq_value_name").query("{body.uniq_value_id:'some_id1'}").as(String.class); - Who cares - everything is described in some detail here: Jongo about - Aeroua

0