Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Done
    • Affects Version/s: 2.0.0
    • Fix Version/s: None
    • Component/s: JavaScript, Querying
    • Labels:
      None
    • Environment:
      All

      Description

      I keep wishing I could have a computed field:

      Basic idea:

      db.people.find( { firstname : "John" }, { _id: 1, name : function() {return this.firstname + ' ' + this.lastname;} } )
      

      Where it gets interesting:

      db.people.find( { score: {'$gt': 10} }, { _id: 1, score: function() {return this.foo + this.bar + this.baz;} } ).sort(score: 5)
      

      Obviously if you know in advance that you're going to need to run a query like this frequently it makes sense to try to precompute the value, but sometimes a query is so rare that precomputing is a waste, and in some cases you don't know enough information in advance.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                6 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: