Mongo Collation Support - #14188
Mongo Collation Support#14188
Conversation
✅ Deploy Preview for v3-meteor-api-docs canceled.
|
✅ Deploy Preview for v3-migration-docs canceled.
|
|
@italojs - Do you want me to resolve the conflicts? |
|
@mvogttech feel free to handle it. thanks ;) |
…ongo.Sorter calls in both the changeStreams and oplog sections of the new structure
…h/meteor into mongo-collation-support
radekmie
left a comment
There was a problem hiding this comment.
It's hard for me to tell, whether Intl.Collator and MongoDB's collation are truly compatible, but overall it looks correct. I'm only thinking about making some of the tests run both on the client and the server to check for that.
The client+server test parity should help catch any Intl.Collator vs MongoDB divergence — both sides now run the same find, sort, inequality, and strength-1 tests against the same data. If we find edge cases where they diverge, we can add targeted tests for those. Based on my research Mongo's collation is based on Int.Collator. They are very similar. |
radekmie
left a comment
There was a problem hiding this comment.
As far as I'm concerned, this one looks solid.
…port" This reverts commit 8f9a2ba.
find,findOne,findOneAsync, andobserveChangesIntl.Collator, so client and server behave identicallyMotivation
Previously, collation options passed to
Collection.find()were silently dropped by the mongo driver's cursor whitelist, and Minimongo had no concept of locale-aware string comparison at all. This forced workarounds likegenerateCasePermutationsForString, which builds 16-clause$orqueries for case-insensitive lookups.With this PR, a simple
{collation: {locale: 'en', strength: 2}}option enables case-insensitive matching on both client and server, using MongoDB's native collation on the server andIntl.Collatorin Minimongo. Since Minimongo now understands collation, the oplog observe driver can correctly filter oplog events for collation queries without falling back to polling.Changes
Minimongo (
packages/minimongo/)matcher.jsMatcheracceptscollationparam, createsIntl.Collatorvia_createCollator. Threads collator through_cmpand_equalfor all string comparisons. Scalar_idfast path falls through to document selector compilation when collation is active.common.jsequalityElementMatcherand inequality operators ($gt,$gte,$lt,$lte,$eq,$ne,$in,$nin) accept and pass through the collator.sorter.jsSorteracceptscollationparam, passes collator to_cmpin_keyFieldComparator.cursor.jsoptions.collationtoMatcherandSorter. Skips_selectorIdfast path when collation is present (directIdMap.getis not collation-aware).Mongo driver (
packages/mongo/)mongo_connection.jscollationto themongoOptionswhitelist in_createAsynchronousCursor. PassescursorDescription.options.collationtoMinimongo.MatcherandMinimongo.Sorterin_observeChanges.cursor_description.tsCollationOptionsinterface andcollation?field toCursorOptions.package.jscollation_tests.jsinonTest.Documentation
collection/methods_sync.js@param options.collationtofind()andfindOne()JSDoc.collection/methods_async.js@param options.collationtofindOneAsync()JSDoc.docs/source/api/collections.mdpackages/minimongo/README.mdCollation option mapping
MongoDB collation options are mapped to
Intl.Collatoras follows:strength: 1sensitivity: 'base'cafe=Café)strength: 2sensitivity: 'accent'alice=Alice,cafe≠café)strength: 3(default)sensitivity: 'variant'strength: 1+caseLevel: truesensitivity: 'case'numericOrdering: truenumeric: true'2'sorts before'10'caseFirst: 'upper'/'lower'caseFirst: 'upper'/'lower'Usage example