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.ToObjectmust 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:
- humhei/LiteDB, branch
MyDev2: 2 commits not in upstream (compare withdev) - humhei/LiteDB, branch
patch-1: 1 commit not in upstream (compare withdev)
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/
MyDev2commits (39ce8d487e, e34d8769c0, 499f436d5f, test 2ff2b50d37), with humhei asCo-authored-by. - In
BsonDocument.csandBsonArray.cs, changepublic override int CompareTo(BsonValue other)toCompareTo(BsonValue other, Collation collation). - Forward
collationto element comparisons, and pass it fromBsonValue.cs:588-589. - Check the test: its second assertion
((BsonValue)a).CompareTo(b) == 0expects the parameterless overload to be case-insensitive. - On dev that overload is
Binaryby design. Keep only the collation-aware assertion (or useCollation.Defaultexplicitly). - 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.
Source: litedb-org/LiteDB