Details
-
Task
-
Resolution: Done
-
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.
|