Right now I got:
@directories = collection.directories.all.asc(:name)
But it's case-sensitive, how do I do case-insensitive sorting?
Database names and Collection names are case sensitive. You can always recreate the DB/Collection with the appropriate name.
MongoDB can perform sort operations on a single-field index in ascending or descending order. In compound indexes, the sort order determines whether the index can be sorted. The sort keys must be listed in the same order as defined in the index.
To sort documents in MongoDB, you need to use sort() method. The method accepts a document containing a list of fields along with their sorting order. To specify sorting order 1 and -1 are used. 1 is used for ascending order while -1 is used for descending order.
Currently you cannot create case insensitive indexes in MongoDB see ...
http://jira.mongodb.org/browse/SERVER-90
So, it seems that means you cannot do case insensitive "sorting" either.
You can upvote the feature for future inclusion in MongoDB via the link above if you find it useful.
Eliot Horowitz from 10Gen (the supporters of MongoDB) suggest this in the meantime:
For short term - I would just add a 2nd field that you call .toLower() on before inserting. Then you can sort on that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With