#2859·LiteDB

Collation is ignored when comparing nested documents and arrays

Author: JKamskerCreated Sep 12, 2026Updated Sep 16, 2026
Labelsbugseverity: highpriority: P2from fork

The maintainer of an F#-oriented stack (a LiteDB.FSharp user) needed two things v5 lost:

  • Case-insensitive collation must also apply inside nested documents and arrays (#1980).
  • Overridden BsonMapper.ToObject must be called when reading (#1977).

Still relevant on dev

Pass the collation through when comparing nested BsonDocument/BsonArray values, so that case-insensitive comparisons of documents and arrays work.

Where this comes from

This need showed up in a fork of LiteDB, where it was solved for the owner's own use:

Upstream pull requests from this fork: #1978 (closed).

Credit for the original work goes to humhei.

Would porting the fork's code pay off?

Yes: the fork's change is small and fits dev with little rework.

  • Take humhei's Fixes#1980/MyDev2 commits (39ce8d487e, e34d8769c0, 499f436d5f, test 2ff2b50d37), with humhei as Co-authored-by.
  • In BsonDocument.cs and BsonArray.cs, change public override int CompareTo(BsonValue other) to CompareTo(BsonValue other, Collation collation).
  • Forward collation to element comparisons, and pass it from BsonValue.cs:588-589.
  • Check the test: its second assertion ((BsonValue)a).CompareTo(b) == 0 expects the parameterless overload to be case-insensitive.
  • On dev that overload is Binary by design. Keep only the collation-aware assertion (or use Collation.Default explicitly).
  • Check that no index-key ordering depends on binary nested compare. Documents and arrays are not index keys, so it should not.

If you're the author of that fork: a pull request against dev would be very welcome.