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

Add expression indexes

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Indexing
    • Labels:
      None
    • Backwards Compatibility:
      Major Change
    • Case:

      Description

      An expression index is one where the value being indexed is the result of an expression, like lower casing a string.

      http://en.wikipedia.org/wiki/Expression_index
      http://www.postgresql.org/docs/8.1/static/indexes-expressional.html

      One possible way of specifying the expression could be through the existing aggregation expressions: http://docs.mongodb.org/manual/reference/operator/aggregation/#arithmetic-operators

      db.coll.addIndex("lowercase_name", {$expression: {$toLower:"$name"}});

      Note: In the example above there is no name for the expression, aside from the index name, because any name could conflict with documents. Also, the expression should be used in the query; the query expression may be a sub/superset of the index expression, or multiple indexes.

      Any expression support in indexes requires those expressions be available in the query language as well; it could look like this:

      db.coll.find({$expression: {$eq:["scott", {$toLower:"$name"}]}})

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                13 Vote for this issue
                Watchers:
                24 Start watching this issue

                Dates

                • Created:
                  Updated: