We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I check if a field reference/aggregation expression is null and obtain a boolean?
ConditionalOperators.ifNull("field").then(false)
ComparisonOperators.valueOf("field").equalToValue(null)
BooleanOperators.Or.or(Fields.field("field"))
I just want to obtain $eq: ["$field", null]. Am I missing something?
$eq: ["$field", null]
Workaround
ArrayOperators.arrayOf(List.of("null", "missing")).containsValue((DataTypeOperators.typeOf("field")));
But this results in a different query, I'd like to obtain exactly $eq: ["$field", null].
The text was updated successfully, but these errors were encountered:
Thanks for bringing this to our attention. There does not seem to be an easy way to do this other than providing your own AggregationExpression.
AggregationExpression
AggregationUpdate update = AggregationUpdate.update() .set(SetOperation.builder().set("field").toValue(new AggregationExpression() { @Override public org.bson.Document toDocument(AggregationOperationContext context) { ArrayList<Object> args = new ArrayList<>(2); args.add("$field"); args.add(null); return new org.bson.Document("$eq", args); } }));
We'll look into lifting the restriction on the Eq expression.
Eq
Sorry, something went wrong.
christophstrobl
No branches or pull requests
How can I check if a field reference/aggregation expression is null and obtain a boolean?
ConditionalOperators.ifNull("field").then(false)
- does not return true/falseComparisonOperators.valueOf("field").equalToValue(null)
- throws NPEBooleanOperators.Or.or(Fields.field("field"))
- also returns true if value is 0I just want to obtain
$eq: ["$field", null]
. Am I missing something?Workaround
But this results in a different query, I'd like to obtain exactly
$eq: ["$field", null]
.The text was updated successfully, but these errors were encountered: