`Filters.eq(fieldName, value)` not actually creating `$eq` causes issues

1 week ago 8
ARTICLE AD BOX

I'm not sure if this is a MongoDB issue, an issue with the mongo-java-driver or if I'm doing something worng.

The issue is that MongoDB can behave differently in case there is a $eq operator or if a {fieldName: value} syntax is used. See an example here: https://mongoplayground.net/p/sXKR2FvE5eg

I want to group by the groupBy field and want the type: "A" objects to be in a typeA field and vice versa for B.

I used the mongo-java-driver which does not create $eq operator in case Filter.eq is used, see documentation

For typeA I used $eq in the example and for typeB I used the non-$eq syntax. As the example demonstrates, the $eq operator actually filters correctly, but the non-$eq syntax does not.

So the question is, is this an actual MongoDB issue or should Filters.eq always created an $eq in the mongo-java-driver?

Read Entire Article