Skip to content

4.0.3: legacy query edge cases

Latest

Choose a tag to compare

@taplin taplin released this 04 Oct 19:41
490f490

This release fixes how the legacy query API (the BSON-based find, count and update) handles some edge cases. Since 4.0.0 it has run on libmongoc 2, which removed the old C calls, and in these cases it accepted bad input silently or dropped options.

Fixes

  • Invalid $query documents are rejected. These were accepted silently before; libmongoc 1.x's legacy find rejected both, and so does 4.0.3. (#33)

    • A $query that isn't a document, such as {$query: 5}, made find() and count() match every document.
    • Fields that don't start with $ next to $query were merged into the filter.

    Now count() returns an error, find() returns nil and GridFS list(filter:) throws. A duplicate $query means the last one wins, as it did in 1.x.

  • count() applies more legacy-query options. $hint, $maxTimeMS, $comment and $collation were silently dropped before; they now apply. (#33)

  • Negative limit in count(). It now counts like a positive limit, as the old count command treated it. Before, the server rejected it. (#33)

  • update(selector:update:flag: .multiUpdate) with a replacement document is an error. Before, it replaced one document and reported success. Use an update-operator document such as {$set: …} to update many. (#33)

Behaviour to note

  • count() runs as an aggregate $match, so the query can't use $where, $near or $nearSphere; use $expr, or $geoWithin with $center / $centerSphere. This has been the case since 4.0.0; it's now documented.
  • Code that relied on any of the silent behaviours above will now see an error or nil instead.

No API changes. Tested against MongoDB 8.3 and 8 with libmongoc 2.5.5 on macOS and Linux, and in CI with apt's libmongoc 2.2.2 on Ubuntu 26.04. Full changes: 4.0.2...4.0.3