Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-153

javascript sort helper for custom sorting / indexing

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: planned but not scheduled
    • Component/s: Indexing
    • Labels:
      None

      Issue Links

        Activity

        Hide
        rgpublic rgpublic added a comment -

        @Stephane: No, the title says "custom sorting / indexing". This feature, at least as far as I understand it (@Eliot: please correct me if I'm wrong), means that one would be able to create an index on the functional result of any javascript calculation and subsequently make use of it during a query. Right now, for instance, we are using a property named "folder" with values like "this/is/a/path". At the moment we cannot query the name of the last folder ("path") efficiently. Sorting by the last folder would be similarly problematic. Thus, we have created a second property "_auto_foldername" and try to keep this in sync. You need to do this everywhere in your code where the property changes. Admittedly not really a great solution. Implementing this feature would allow us to get rid of these unnecessary helper properties (we got a lot of them) and just create a special index on say folder.substr(folder.lastIndexOf("/")). Now, the interesting question would be how Mongo will detect when it can use that index. I suppose the easiest most-straightforward method would be to do a hash fingerprint of the function and just compare that. Furthermore, the function would have to be deterministic (i.e. using no random numbers etc). In Oracle you have to guarantee that by adding the keyword DETERMINISTIC to your PL/SQL function. Don't know if we really need that. Oracle isnt able to check if this is true anyway. It's just a keyword.

        Show
        rgpublic rgpublic added a comment - @Stephane: No, the title says "custom sorting / indexing ". This feature, at least as far as I understand it (@Eliot: please correct me if I'm wrong), means that one would be able to create an index on the functional result of any javascript calculation and subsequently make use of it during a query. Right now, for instance, we are using a property named "folder" with values like "this/is/a/path". At the moment we cannot query the name of the last folder ("path") efficiently. Sorting by the last folder would be similarly problematic. Thus, we have created a second property "_auto_foldername" and try to keep this in sync. You need to do this everywhere in your code where the property changes. Admittedly not really a great solution. Implementing this feature would allow us to get rid of these unnecessary helper properties (we got a lot of them) and just create a special index on say folder.substr(folder.lastIndexOf("/")). Now, the interesting question would be how Mongo will detect when it can use that index. I suppose the easiest most-straightforward method would be to do a hash fingerprint of the function and just compare that. Furthermore, the function would have to be deterministic (i.e. using no random numbers etc). In Oracle you have to guarantee that by adding the keyword DETERMINISTIC to your PL/SQL function. Don't know if we really need that. Oracle isnt able to check if this is true anyway. It's just a keyword.
        Hide
        serbrech stephane erbrech added a comment -

        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.

        Show
        serbrech stephane erbrech added a comment - 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.
        Hide
        ihristov Ivan Hristov added a comment -

        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.

        Show
        ihristov Ivan Hristov added a comment - 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.
        Hide
        flashy Lukas Gutschmidt added a comment -

        Something like Views in Couchbase. I need that so badly.

        Show
        flashy Lukas Gutschmidt added a comment - Something like Views in Couchbase. I need that so badly.
        Hide
        liqiang Qiang Li added a comment -

        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.

        Show
        liqiang Qiang Li added a comment - 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.

          People

          • Votes:
            101 Vote for this issue
            Watchers:
            62 Start watching this issue

            Dates

            • Created:
              Updated:
              Days since reply:
              30 weeks ago
              Date of 1st Reply: