Add query support for $collation (Mongo 3.4+)

Aperta
#70 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, mongodb
Ambito
database

Direzione di ricerca

Inizia in index.js, nella mappa delle proprietà di query con prefisso dollaro a cui fa riferimento la issue, poi esamina .travis.yml per i valori di MONGODB_VERSION e trova i test delle query esistenti. Esegui i test pertinenti sulle versioni supportate di MongoDB; il lavoro è completato quando $collation funziona sui server compatibili e le versioni precedenti producono un comportamento di errore sensato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Background

Mongo 3.4 added support for collation in string comparisons, for finding and sorting. This enables, among other things, sorting while ignoring case and accent differences based on a provided locale.

With a plain Mongo JS client, a case-insensitive sort would use cursor.collation:

db.my_collection.find(query)
  .sort({myStringField: 1})
  .limit(1)
  .collation({locale: 'en_US', strength: 1 /*or 2*/});

With a larger result set, a matching case-insensitive index would also be desirable for performance.

sharedb-mongo doesn't support collations yet in queries. Yet! That's what this is about.

In the meantime, there are some workarounds for doing case-insensitive sorting.

Implementation

Thankfully, it's straightforward to add support in sharedb-mongo for collation.

The usage that's equivalent to the Mongo JS driver example above would look like this:

connection.createSubscribeQuery('my_collection', {
  $sort: { myStringField: 1 },
  $collation: {locale: 'en_US', strength: 1 /*or 2*/},
});

sharedb-mongo has a map from dollar-prefixed query properties to cursor methods, and supporting collation is as easy as adding a $collation entry.

There are a couple additional pieces:

  • Tests: The one slightly tricky part with the tests is that Share runs its tests against Mongo server 2.6, 3.6, and 4.0, and collation won't work when running against 2.6. I believe it should be possible to have the test code check the MONGODB_VERSION env variable set in Travis and conditionally run specific test cases that way.
  • Error handling: Since collation was added in Mongo 3.4, any server versions before that will not handle collation.
    • Whoever implements this should check behavior against older servers and make sure something sensible happens error-wise.
    • Things are mostly fine client-wise. sharedb-mongo depends on mongodb ^2.1.2. That will result in installing [email protected], which does support cursor.collation. Users can pass in a pre-created Mongo client, though, which may be an issue.
Lingua principale
JavaScript
Stelle
152
Fork
68
Merge medio
52m
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di share/sharedb-mongo

Tutte le issue di share/sharedb-mongo

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.