Hi
I am managing a long overdue java driver upgrade from v3.12.7 to v4.11.1 and when using a filter in a MongoCollection.find(filter), I am now getting the error:
‘$and/$or/$nor must be a nonempty array’
I believe it’s linked to way I build my filters. They are a combination of AndQueries with OrQueries, so a typical query with just an AndQuery and no OrQuery would look like this:
And Filter{filters=[And Filter{filters=[Filter{fieldName='_id', value=some-id}]}, And Filter{filters=[]}]}
When I would convert this query to Json, I would get -
In v3.12.7:
result = bson.toBsonDocument(classOf[BsonDocument],
MongoClient.getDefaultCodecRegistry).toJson
result = {"_id": "some-id"}
In v4.11.1:
result = bson.toBsonDocument().toJson
result = {"$and": [{"$and": [{"_id": "some-id"}]}, {"$and": []}]}
I believe the error comes from the additional ands, which is correct, given my bson filter. Is there a way to get my queries to ignore the nonempty arrays, similar to v3.12.7?
My current workaround is to replace the empty and section with Filters.empty() but it is legacy code so I am reluctant to change too much.