0

I have a collection with repeated values for columns in the documents. I want to query for distinct values of multiple fields(System, subsystem) combination. Below is a sample data:

"System" : "training", "subsystem": "user", "ccid": "post", ret: 0
"System": "training", "subsystem": "user", "ccid": "test", ret: 1
"System": "training", "subsystem ":"cour", "ccid":"sample", ret:0

I tried to use the aggregate from the other links, but it's not resolving in java for me. Could you please share me a sample java code using aggregate or map-reduce or any of the suitable methods

jmattheis
  • 10,494
  • 11
  • 46
  • 58
vk l
  • 33
  • 4
  • Have you tried using [$group](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#-group--aggregation-) – Joe Dec 31 '22 at 10:29
  • Could you please share the java syntax of aggregate group for this scenario? I tried, but couldn't get the correct syntax – vk l Jan 01 '23 at 05:10
  • This might help: https://stackoverflow.com/questions/42814325/spring-data-mongodb-group-by – Joe Jan 01 '23 at 19:04
  • @Joe: I don't have a class defined for the structure. Could you share me a simple java query including aggregate group of 2 fields and projection fields? – vk l Jan 02 '23 at 11:22
  • I have formed this query: cursor1= CollSubsystem.aggregate(Arrays.asList(Aggregates.match(filter),Aggregates.project(SubSystemFields))).iterator() ; In order to add group iteria, it's expecting BSON Format, i tried addfields also -> that's expecting field format. Please advise. – vk l Jan 02 '23 at 13:04

0 Answers0