[SERVER-153] javascript sort helper for custom sorting / indexing Created: 13/Jul/09 Updated: 22/Mar/23 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Index Maintenance |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Eliot Horowitz (Inactive) | Assignee: | Backlog - Query Integration |
| Resolution: | Unresolved | Votes: | 106 |
| Labels: | js-in-agg, udf | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Assigned Teams: |
Query Integration
|
||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Comments |
| Comment by Qiang Li [ 06/Jul/16 ] | |||||||
|
I know this is irrelevant. I tried PostgreSQL. It has got great jsonb support since 9.4. what's more, you can have the best of both worlds. | |||||||
| Comment by Billy Tetrud [ 06/Jul/16 ] | |||||||
|
Being able to create custom indexes would be incredibly helpful. The most general way I can see this being done is something like this:
The named index would map the result of the given expression to the _ids with that result. You could then use that index for searching or sorting. This would be incredibly and open a huge number of potential optimizations without being required to store that data in each individual document. | |||||||
| Comment by Diego Pamio [ 06/May/16 ] | |||||||
|
We need it for the following use case:
| |||||||
| Comment by Qiang Li [ 05/Feb/15 ] | |||||||
|
We would like to sort by computed values based on some time related fields. e.g. a document will be listed at the top if today is in its date range. it will not be practical to store precomputed values. | |||||||
| Comment by Lukas Gutschmidt [ 12/Jan/13 ] | |||||||
|
Something like Views in Couchbase. I need that so badly. | |||||||
| Comment by Ivan Hristov [ 25/Oct/12 ] | |||||||
|
This will be really a great feature. I'm especially interested in transforming a string field representing a number and then sorting by the number. | |||||||
| Comment by stephane erbrech [ 14/Feb/12 ] | |||||||
|
Ok, thanks for details. That would for sure be useful. though overkill for my use case that only needs to return null last when sorting. | |||||||
| Comment by rgpublic [ 14/Feb/12 ] | |||||||
|
@Stephane: No, the title says "custom sorting / indexing | |||||||
| Comment by stephane erbrech [ 14/Feb/12 ] | |||||||
|
Wouldn't this mean tha mongodb will have to iterate over the whole collection to sort the result? @NickHoffman to do this, I think there could/should be a much simpler sort option, like in SQL : null last, or null first. | |||||||
| Comment by Nick Hoffman [ 06/Feb/12 ] | |||||||
|
That would be a very, very useful improvement to MongoDB, then. Thanks, Eliot. | |||||||
| Comment by Eliot Horowitz (Inactive) [ 06/Feb/12 ] | |||||||
|
@nick - yes | |||||||
| Comment by Nick Hoffman [ 03/Feb/12 ] | |||||||
|
Could this be used to sort alphabetically on a field, and put documents with a null value at the end of the result set? | |||||||
| Comment by Wei Kong [ 22/Oct/11 ] | |||||||
|
I have an array defined. For example: [ {"name":"food", "value":1}, {"name":"car", "value":2}] I would like to be able to sort by the value but on those with name either match "food" or "car" | |||||||
| Comment by Stanislav O. Pogrebnyak [ 27/Sep/11 ] | |||||||
|
I see that some thing like: db.coll1.find().sort({ }).limit(100) I could even add tests, or help with implementation, since i have some C++/STL/boost backgrounds. That could be very useful feature | |||||||
| Comment by Nic Cottrell (Personal) [ 14/May/11 ] | |||||||
|
I would like to be able to sort the results based on a parameter, in this case the length of an example sentence I am doing a fuzzy match for. I'd like to be able to sort by something like: "-Math.abs(textLength-28)" and be able to pass a parameter instead of a hardcoded value. | |||||||
| Comment by Keith Branton [ 23/Feb/11 ] | |||||||
|
I'd love to see a little detail on what this means. If this is going to allow the use of expressions in sorts and "function indexes" then I wish I had more than one vote! |