Scala driver: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.client.model.BsonField

2,644 views
Skip to first unread message

Yann Simon

unread,
Dec 18, 2015, 10:57:58 AM12/18/15
to mongodb-user
Hi,

I'm trying to use the aggregate with the scala driver, but I have the following error:

Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class com.mongodb.client.model.BsonField.
at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46) ~[mongo-java-driver-3.1.1.jar:na]
at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63) ~[mongo-java-driver-3.1.1.jar:na]
at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37) ~[mongo-java-driver-3.1.1.jar:na]
at com.mongodb.client.model.BuildersHelper.encodeValue(BuildersHelper.java:35) ~[mongo-java-driver-3.1.1.jar:na]
at com.mongodb.client.model.Aggregates$1.toBsonDocument(Aggregates.java:129) ~[mongo-java-driver-3.1.1.jar:na]
at com.mongodb.async.client.AggregateIterableImpl.createBsonDocumentList(AggregateIterableImpl.java:185) ~[mongodb-driver-async-3.2.0.jar:na]
at com.mongodb.async.client.AggregateIterableImpl.execute(AggregateIterableImpl.java:151) ~[mongodb-driver-async-3.2.0.jar:na]
at com.mongodb.async.client.AggregateIterableImpl.batchCursor(AggregateIterableImpl.java:141) ~[mongodb-driver-async-3.2.0.jar:na]
at com.mongodb.async.client.MongoIterableSubscription.requestInitialData(MongoIterableSubscription.java:48) ~[mongodb-driver-async-3.2.0.jar:na]
at com.mongodb.async.client.AbstractSubscription.tryRequestInitialData(AbstractSubscription.java:151) ~[mongodb-driver-async-3.2.0.jar:na]
at com.mongodb.async.client.AbstractSubscription.request(AbstractSubscription.java:82) ~[mongodb-driver-async-3.2.0.jar:na]

I tried to add codec registries but it does not help.
What I am using now:
val codecRegistry = CodecRegistries.fromProviders(
new ValueCodecProvider(),
new DBObjectCodecProvider(),
new BsonValueCodecProvider())
I tried to add codec registries but it does not help.
Any idea?

Thanks in advance!
Yann

Jeff Yemin

unread,
Dec 18, 2015, 11:30:01 AM12/18/15
to mongodb-user
Hi Yann,

Can you post a code snippet for the generation of the aggregation pipeline that causes this exception?


Thanks,
Jeff

Yann Simon

unread,
Dec 18, 2015, 11:41:20 AM12/18/15
to mongodb-user
Here it is:
import org.mongodb.scala.model.Aggregates._
import org.mongodb.scala.model.Filters._ import org.mongodb.scala.model.Accumulators._
coll.aggregate(List(
filter(equal("target.typeId", "product")),
group(avg("averageRating", "$rating")),
out("rating")
))
It may not make sense for mongo - I am just trying to use the aggregate function.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/394d69a9-1353-4c22-a7ab-a2d259d895df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeff Yemin

unread,
Dec 18, 2015, 12:16:31 PM12/18/15
to mongodb-user
Ah, I see it.  Try passing an id for the group stage, e.g.

coll.aggregate(List(
filter(equal("target.typeId", "product")),
  group(null, avg("averageRating", "$rating")),
out("rating")
))


Regards,
Jeff

Yann Simon

unread,
Dec 18, 2015, 2:40:14 PM12/18/15
to mongodb-user
Thanks for this very useful suggestion!

Reply all
Reply to author
Forward
0 new messages