[JAVA-1763] CodecConfigurationException when using Filters class with aggregation Created: 15/Apr/15 Updated: 03/Jun/22 Resolved: 15/Feb/19 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | 3.0.0 |
| Fix Version/s: | 3.11.0 |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Jochen Kemnade | Assignee: | Ross Lawley |
| Resolution: | Done | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
I use com.mongodb.client.MongoCollection.aggregate(List<? extends Bson>) with an aggregation pipeline that contains $match directives. I build some of them with the com.mongodb.client.model.Filters class. When executing the aggregation I get an exception:
|
| Comments |
| Comment by Ross Lawley [ 08/Feb/19 ] | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 02/Oct/15 ] | ||||||||||||||||||||||||||||||||||||
|
Thanks. What you mention as 1. and 3. are exactly my points. | ||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 01/Oct/15 ] | ||||||||||||||||||||||||||||||||||||
|
I have a somewhat different view of the Bson interface. The reason it was added was to give users the flexibility to pass instances of different Bson-implementing classes to the various methods in MongoCollection and MongoDatabase. The use cases we had in mind were:
But we did not mean to require that different implementation of Bson must interoperate. For example, the BsonDocument class can only contain values of type BsonValue, but not other Bson types. That said, we still could decide to allow arbitrary Bson values inside Document. So I'm going to re-open this issue so we can consider it further. | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 01/Oct/15 ] | ||||||||||||||||||||||||||||||||||||
|
What about something like this? | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 01/Oct/15 ] | ||||||||||||||||||||||||||||||||||||
|
To be honest, I find this quite hard to accept. I think this goes against the whole point of the Bson interface. I think it is there to give the users the freedom to use different implementations (like Filters, BasicDBObject, and Document). If those implementations cannot be used together, it is nearly impossible to base any code on the Bson interface, because code written by different people could use different incompatible implementations. | ||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 01/Oct/15 ] | ||||||||||||||||||||||||||||||||||||
|
Hi Jochen, This ticket was closed as Works As Designed, so I wouldn't expect either of those scripts to work with 3.1. The 3.1 release only offers an alternative: use the new Aggregates static factory methods to construct the pipeline, e.g.
Please see the reference documentation for more examples. | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 01/Oct/15 ] | ||||||||||||||||||||||||||||||||||||
|
flozano, 3.1 changes things for you? I just tried both scripts with 3.1.0-rc0 and they still break. | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 15/Sep/15 ] | ||||||||||||||||||||||||||||||||||||
|
We've almost completely stopped using the Filters class because it causes those errors. | ||||||||||||||||||||||||||||||||||||
| Comment by Francisco Alejandro Lozano López [ 15/Sep/15 ] | ||||||||||||||||||||||||||||||||||||
|
It is - here we're using 3.1-SNAPSHOT because of it... | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 15/Sep/15 ] | ||||||||||||||||||||||||||||||||||||
|
3.0.4 is still affected. | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 09/Jul/15 ] | ||||||||||||||||||||||||||||||||||||
|
This groovy script reproduces the issue. | ||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 09/Jul/15 ] | ||||||||||||||||||||||||||||||||||||
|
jkemnade can you post your application code that is calling the count method where this exception is thrown? | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 09/Jul/15 ] | ||||||||||||||||||||||||||||||||||||
|
A similar thing also happens when combining Document and Filters with com.mongodb.client.MongoCollection.count(Bson).
| ||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 11/May/15 ] | ||||||||||||||||||||||||||||||||||||
|
There's no good place where a better error message could be inserted, so I think we're going to have to live with this. Note that the Aggregates class is available in 3.1-SNAPSHOT now. | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 15/Apr/15 ] | ||||||||||||||||||||||||||||||||||||
|
Thanks for your help. Could the error message be improved until then to help users understand that they should not (yet) combine Filters and Documents? | ||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 15/Apr/15 ] | ||||||||||||||||||||||||||||||||||||
|
The current plan for aggregate pipeline builders would have it look something like this:
or with static imports in place, just:
We should have this available in a 3.1 SNAPSHOT in a couple of weeks. Until then, apologies for the inconvenience, and please follow ross@10gen.com's advice above. | ||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 15/Apr/15 ] | ||||||||||||||||||||||||||||||||||||
|
Currently mixing Filters inside Documents is not supported, without adding a custom codecs. We are writing static helpers for aggregation for 3.1 ( In the meantime it may be easier to use just documents or parse Json:
| ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 15/Apr/15 ] | ||||||||||||||||||||||||||||||||||||
|
I attached a Groovy script to reproduce the problem. | ||||||||||||||||||||||||||||||||||||
| Comment by Jochen Kemnade [ 15/Apr/15 ] | ||||||||||||||||||||||||||||||||||||
|
I guess the problem is caused by combining org.bson.Document and com.mongodb.client.model.Filters.
leads to
| ||||||||||||||||||||||||||||||||||||
| Comment by Ross Lawley [ 15/Apr/15 ] | ||||||||||||||||||||||||||||||||||||
|
Can you post an example of your aggregation pipeline code? |