This repository has been archived by the owner on Mar 15, 2023. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds MongoDB collation support to the
find
,remove
andpatch
methods. Using collations, it's possible to perform case-insensitive and locale-aware queries.I'm not sure what the built-in version of MongoDB is on Travis CI. This PR will likely fail to build if using < v3.4. See Potential Problems below.
MongoDB introduced collation support in v3.4 see the Release Notes for MongoDB 3.4 – Collation and Case Insensitive Indexes for more information on the feature.
This pull request implements collation support via a
collation
parameter passed tofind()
,remove()
andpatch()
. Tests are included in this PR, but here are some quick examples on how this could be used:Example: Patch records with case-insensitive alphabetical ordering.
The example below would patch all student records with grades of
"c"
or"C"
and above (a natural language ordering). Without collations this would not be as simple, since the comparison{ $gt: "c" }
would not include uppercase grades of"C"
because the binary codepoint of"C"
is less than"c"
.Example: Find records with a case-insensitive search.
Similar to the above example, this would find poor students by their grades, in a case-insensitive manner.
Potential Problems
One potential problem I see with the
update()
method, is that acollation
member must be added to the query passed to MongoDB. MongoDB's documentation on this is a little vague... it seems that you would set thecollation
member on theoption
parameter, but that does not work. This could lead to a collision when updating records with acollation
member. I'm open to suggestions on how to solve this. Since MongoDB v3.4 is so young, there's not a lot of discourse available on the best way to uses these new features.Another potential issue is that the collation support is (obviously) not available on MongoDB version < v3.4. It would be nice to throw an error if someone attempts to use the
collation
parameter with an older version of MongoDB. But... only a reference to the collection is passed to the service, which precludes checking thedb
version without hacking a reference to the parentdb
instance through the collection. I'm not a MongoDB ace–maybe there's a simple way to check the MongoDB version that I'm unaware of.- Disclaimer -
I've implemented
collation
as a parameter because to me, that seems like the most natural way to use it. I'm relatively new to using Feathers... and I know one of the main selling points of using Feathers is the ability to "drop-in" other storage engines. So I'm not sure if there's a philosophical resistance to implementing database-specific features. It seems, however, that other database adapters do exactly that (KnexJS for example, implements a special$like
filter). If there's a more appropriate way of implementing this feature, please let me know. I'd be glad to modify the PR.