Core Server
  1. Core Server
  2. SERVER-153

javascript sort helper for custom sorting / indexing

    Details

    • Type: New Feature New Feature
    • Status: Open Open
    • Priority: Major - P3 Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: planned but not scheduled
    • Component/s: Indexing
    • Labels:
      None
    • # Replies:
      12
    • Last comment by Customer:
      true

      Issue Links

        Activity

        Hide
        stephane erbrech
        added a comment -

        Wouldn't this mean tha mongodb will have to iterate over the whole collection to sort the result?
        This is rarely a good option.

        @NickHoffman to do this, I think there could/should be a much simpler sort option, like in SQL : null last, or null first.

        Show
        stephane erbrech
        added a comment - Wouldn't this mean tha mongodb will have to iterate over the whole collection to sort the result? This is rarely a good option. @NickHoffman to do this, I think there could/should be a much simpler sort option, like in SQL : null last, or null first.
        Hide
        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
        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
        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
        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
        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
        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
        Lukas Gutschmidt
        added a comment -

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

        Show
        Lukas Gutschmidt
        added a comment - Something like Views in Couchbase. I need that so badly.

          People

          • Votes:
            90 Vote for this issue
            Watchers:
            49 Start watching this issue

            Dates

            • Created:
              Updated:
              Days since reply:
              1 year, 13 weeks, 4 days ago
              Date of 1st Reply: