Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-750

Index FAQ: Arbitrary Attributes

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Use the following as the basis for the question.

      Using a Multikey Index for Attribute Lookups
      ````````````````````````````````````````````
       
      For simple attribute lookups, an effective indexing strategy can be to
      index a field that contains an array of documents. For example, the
      ``attrib`` field in the following document allows you to add an
      unlimited number of attributes types:
       
      .. code-block:: javascript
       
         { _id : ObjectId(...),
           attrib : [
                     { color: "red" },
                     { shape: "rectangle" },
                     { color: "blue" },
                     { avail: true }
                    ]
         }
       
      The following queries would *both* use the multikey index:
       
      .. code-block:: javascript
       
         db.mycollection.find( { attribs: { color: "blue" } } )
         db.mycollection.find( { attribs: { avail: false } } )
       
      Use this kind of indexing strategy for simple attribute lookups rather
      than sorted query results or range queries.

      Attachments

        Activity

          People

            bgrabar Bob Grabar
            sam.kleinman Sam Kleinman (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              11 years, 13 weeks, 6 days ago