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

5
  • Have you tried using $group Commented Dec 31, 2022 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 Commented Jan 1, 2023 at 5:10
  • This might help: stackoverflow.com/questions/42814325/… Commented Jan 1, 2023 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? Commented Jan 2, 2023 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. Commented Jan 2, 2023 at 13:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.