Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-3600

Aggregation to Java -> Group -> eq instead of DBObject

      Hello,

      I convert an aggregation that works in Compass to Java, and it throws an exception. I have to make some very small changes to the group part to make it work (in Java, replace eq with new BasicDBObject). Is this a bug?

      This aggregation, in MongoDB Compass 1.17.0:
      {{[ {
       $match : {
        "source" : "Kraken",
        "currencyFrom" : "XXBT",
        "currencyTo" : "ZEUR",}}
      {{ }
      }, {
       $group : {
        "_id" : {
         "$toDate" : {
          "$multiply" : [ {
           "$floor" : {
            "$divide" : [

      {        "$toLong" : "$date"       }

      , 3600000 ]
           }
          }, 3600000 ]
         }
        },
        "ct" :

      {    "$sum" : 1   }

      ,
        "min" :

      {    "$min" : "$value"   }

      ,
        "avg" :

      {    "$avg" : "$value"   }

      ,
        "max" :

      {    "$max" : "$value"   }

       }
      } ]}}
      Converts to Java: (in Compass)

      Arrays.asList(match(and(eq("source", "Kraken"), eq("currencyFrom", "XXBT"), eq("currencyTo", "ZEUR"))), group(eq("$toDate", eq("$multiply", Arrays.asList(eq("$floor", eq("$divide", Arrays.asList(eq("$toLong", "$date"), 3600000L))), 3600000L))), sum("ct", 1L), min("min", "$value"), avg("avg", "$value"), max("max", "$value")))

      Which results in this exception:

      Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.client.model.Filters$SimpleEncodingFilter.
       at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46)
       at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63)
       at org.bson.codecs.configuration.ChildCodecRegistry.get(ChildCodecRegistry.java:51)
       at com.mongodb.DBObjectCodec.writeValue(DBObjectCodec.java:230)
       at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:148)
       at com.mongodb.DBObjectCodec.encode(DBObjectCodec.java:64)
       at org.bson.BsonDocumentWrapper.getUnwrapped(BsonDocumentWrapper.java:195)
       at org.bson.BsonDocumentWrapper.entrySet(BsonDocumentWrapper.java:165)
       at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:109)
       at org.bson.codecs.BsonDocumentCodec.encode(BsonDocumentCodec.java:41)
       at com.mongodb.client.model.BuildersHelper.encodeValue(BuildersHelper.java:33)
       at com.mongodb.client.model.Aggregates$GroupStage.toBsonDocument(Aggregates.java:735)
       at com.mongodb.client.internal.AggregateIterableImpl.getOutCollection(AggregateIterableImpl.java:178)
       at com.mongodb.client.internal.AggregateIterableImpl.asReadOperation(AggregateIterableImpl.java:152)
       at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:132)
       at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:86)
       at com.***.web.Database.getExchangeRatesAgg(Database.java:85)
       at com.***.web.Database.main(Database.java:96)

      In order to fix it, in the group part, I had to replace "eq" with "new BasicDBObject".

      Is this a bug in Compass?

      Kind regards,

            Assignee:
            Unassigned Unassigned
            Reporter:
            andre.powroznik@capgemini.com Andre Powroznik
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: