Uploaded image for project: 'MongoDB for IntelliJ Plugin'
  1. MongoDB for IntelliJ Plugin
  2. INTELLIJ-168

how to support parts of MQL expressions in multiple queries (for example, databases, collections or filters)

    • Type: Icon: Investigation Investigation
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • 3
    • Developer Tools

      public List<Document> queryMoviesByYear(String year) {
              MovieAggregationService service = new MovieAggregationService(client.getDatabase("sample_mflix").getCollection("movies"));
              return service.queryMoviesByYear(year);
          }
      
          class MovieAggregationService {
              private final MongoCollection<Document> collection;
      
              public MovieAggregationService(MongoCollection<Document> collection) {
                  this.collection = collection;
              }
      
              public List<Document> queryMoviesByYear(String year) {
                  return collection.aggregate(createPipeline(year)).into(new ArrayList<>());
              }
      
              private List<Bson> createPipeline(String year) {
                  return List.of(
                      Aggregates.match(Filters.eq("year", year)),
                      Aggregates.group("newField",
                          Accumulators.avg("test", "$year"),
                          Accumulators.sum("test2", "$year"),
                          Accumulators.bottom("field", Sorts.ascending("year"), "$year")
                      ),
                      Aggregates.project(Projections.fields(Projections.include("year", "plot"))),
                      Aggregates.sort(Sorts.orderBy(Sorts.ascending("asd", "qwe")))
                  );
              }
          }

            Assignee:
            Unassigned Unassigned
            Reporter:
            kevin.mas@mongodb.com Kevin Mas Ruiz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: