谁有相同的错误以及如何解决?
Java代码:
// For simplify code I left one criteria elemMatch in all criteria.
Criteria expectedCriteria = Criteria.where("tags").all(new Criteria().elemMatch(Criteria.where("localization").is("EN")));
String json = expectedCriteria.getCriteriaObject().toJson();
例外:
Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.springframework.data.mongodb.core.query.Criteria.
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.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:184)
at org.bson.codecs.DocumentCodec.writeIterable(DocumentCodec.java:207)
at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:180)
at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:199)
at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:182)
at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:199)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:141)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45)
at org.bson.Document.toJson(Document.java:313)
at org.bson.Document.toJson(Document.java:286)
at org.bson.Document.toJson(Document.java:273)
文档: https://docs.mongodb.com/manual/reference/operator/query/all/#use-all-with-elemmatch
mongo-java-driver版本在复制中: (在所有) -3.4.3 -3.5.0 -3.6.4 -3.7.1 -3.8.2 -3.9.0
适用于代码的Mongo DB脚本:
db.getCollection('devices').find({
"tags": {
"$all": [{
"$elemMatch": {
"key": "localization",
"value": {
"$eq": "EN"
}
}
}
]
}
})