Skip to content

MongoDB wire: a filter on a null-valued field never matches, because it compiles to "= :param" instead of IS NULL #6952

Closed

Description

@lvca

Summary

Found while fixing #6941 (upsert-by-_id duplicate creation). MongoDBToSqlTranslator.buildExpression translates any scalar filter value, including null, into "field" = :param with the parameter bound to null:

} else {
  buffer.append(quoteFieldPath(entry.getKey()));
  buffer.append(" = ");
  buildValue(buffer, params, value);
}

An equality comparison against a bound null parameter does not match a stored null (or absent) property the way SQL's IS NULL does. So any Mongo filter of the shape {field: null} - a legal and not-uncommon query, since MongoDB's null-equality semantics also match a genuinely missing field - matches nothing in find, update, and delete, regardless of what's actually stored.

Repro

collection.updateOne(eq("_id", null), new Document("$set", new Document("v", 1)), new UpdateOptions().upsert(true));
// creates a document with _id: null

collection.updateOne(eq("_id", null), new Document("$set", new Document("v", 2)), new UpdateOptions().upsert(true));
// does NOT find the document just created; upserts a second one instead

Same gap applies to find(eq("anyField", null)) and deleteOne/deleteMany on a null-valued filter - not specific to _id or to upsert.

Suggested fix

In buildExpression (and the $eq handling that shares the same buildValue call), special-case a null value to emit "field" IS NULL instead of "field" = :param, matching MongoDB's actual null/missing-field semantics as closely as the engine's IS NULL allows.

Scope / confidence

Medium-high on the mechanism (verified buildValue/buildExpression never special-case null, and reproduced the non-match empirically), but the fix touches filter translation shared by find/update/delete/$eq, so it deserves its own review and test pass rather than being folded into the unrelated #6941 upsert fix.

Activity

  1. added a commit that references this issue on Aug 31, 2026
  2. added this to the 26.9.1 milestone on Aug 31, 2026
  3. added
    in progress
    on Aug 31, 2026
  4. self-assigned this
    on Aug 31, 2026
  5. added a commit that references this issue on Sep 1, 2026
  6. lvca commented on Sep 1, 2026

    @lvca
    MemberAuthor

    Fixed in #6969.

    A query filter on a null value (e.g. `{field: null}`) now correctly matches documents where that field is null or missing, instead of matching nothing. This fixes `find`, `update`, `delete`, and also makes a repeated upsert filtered by a null `_id` idempotent.


    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progress
    on Sep 1, 2026
  8. added a commit that references this issue on Sep 1, 2026
  9. added
    mongodb-wire
    on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugmongodb-wire

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions