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
        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.
        Hide
        dpamio Diego Pamio added a comment -

        We need it for the following use case:

        var myPerceptualHash = '0239582305980';
        db.coll1.find().sort({ 
            $by : function( a, b ) {
                var hummingDistance = require('humming-distance');
                return hummingDistance(myPerceptualHash, a.phash) < hummingDistance(myPerceptualHash, b.phash;
            }
        }).limit(1)
        

        Show
        dpamio Diego Pamio added a comment - We need it for the following use case: var myPerceptualHash = '0239582305980'; db.coll1.find().sort({ $by : function( a, b ) { var hummingDistance = require('humming-distance'); return hummingDistance(myPerceptualHash, a.phash) < hummingDistance(myPerceptualHash, b.phash; } }).limit(1)
        Hide
        fresheneesz Billy Tetrud added a comment - - edited

        Being able to create custom indexes would be incredibly helpful. The most general way I can see this being done is something like this:

          // create the index
          db.MyCollection.createNamedIndex({name: "mod5", $expr:function(doc) {
            return doc.value%5
          }))
         
          // use the index
          db.MyCollection.find({x:5, $or[{value:100}, {$namedIndex: {name:'mod5', match: {$lt:1}}}]}).sort({$namedIndex: {name:'mod5', direction: -1}})
        

        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.

        Show
        fresheneesz Billy Tetrud added a comment - - edited Being able to create custom indexes would be incredibly helpful. The most general way I can see this being done is something like this: // create the index db.MyCollection.createNamedIndex({name: "mod5", $expr:function(doc) { return doc.value%5 }))   // use the index db.MyCollection.find({x:5, $or[{value:100}, {$namedIndex: {name:'mod5', match: {$lt:1}}}]}).sort({$namedIndex: {name:'mod5', direction: -1}}) 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.
        Hide
        liqiang Qiang Li added a comment -

        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.
        https://www.postgresql.org/docs/9.4/static/datatype-json.html

        Show
        liqiang Qiang Li added a comment - 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. https://www.postgresql.org/docs/9.4/static/datatype-json.html

          People

          • Votes:
            105 Vote for this issue
            Watchers:
            71 Start watching this issue

            Dates

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