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

Indexing for document keys

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Index Maintenance

      (copied from http://groups.google.com/group/mongodb-user/browse_thread/thread/8d6f4fe174895fda)

      Given a collection like this:

      db.player = {
      name: "Glenn",
      scores: {
      ping_pong:

      { points: 2000 }

      ,
      golf:

      { points: 100 }

      }
      }

      I want an index on each of the keys of scores, so I can efficiently eg. find and sort on 'scores.ping_pong.points'. However, there are too many keys to create indexes on 'scores.ping_pong', 'scores.golf', and so on--there many be hundreds of possible keys.

      It would help if it was possible to create an index on 'scores.$key.points', which would effectively be a compound index on (key name, points), so this type of structure can be indexed without creating an index for every possible key. That way, a single index would work for both find(

      {scores.ping_pong.points: 100}

      ) and find(

      {scores.golf.points: 100}

      ). In the above data, two index entries would be created: one on ('ping_pong', 2000) and the other on ('golf', 100).

      This could probably also be used to accelerate $exists. A (

      {'name': 1, 'scores.$key': 1}

      ) index should allow find({name: 'Glenn', 'scores.ping_pong': {$exists: true}}) to be done efficiently.

      A compound key of ('x', 'scores.$key.points', 'y') would expand to ('x', 'key name', 'points', 'y'). Similarly, ('a.$key.b', 'b.$key.c') expands to ('first key name', 'b', 'second key name', 'c').

            Assignee:
            Unassigned Unassigned
            Reporter:
            glenn Glenn Maynard
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: