@@ -126,3 +126,40 @@ See :ref:`index-selectivity`. If you need to use these,
126
126
it is often best to make sure that an additional, more selective
127
127
criterion is part of the query.
128
128
129
+ Can a multi-key index be used for array matching?
130
+ -------------------------------------------------
131
+
132
+ A multi-key index can be used to look up an exact array match. It does
133
+ so by looking up the first element within the array in the index.
134
+
135
+ What is an effective index strategy for attribute lookups?
136
+ ----------------------------------------------------------
137
+
138
+ For simple attribute lookups, an effective indexing strategy can be to
139
+ create a field that contains an array of documents, each document
140
+ containing a specific type of attribute an its value. You can then index
141
+ that field.
142
+
143
+ For example, the ``attrib`` field in the following document allows you
144
+ to add an unlimited number of attributes types:
145
+
146
+ .. code-block:: javascript
147
+
148
+ { _id : ObjectId(...),
149
+ attrib : [
150
+ { color: "red" },
151
+ { shape: "rectangle" },
152
+ { color: "blue" },
153
+ { avail: true }
154
+ ]
155
+ }
156
+
157
+ The following queries would *both* use the same index:
158
+
159
+ .. code-block:: javascript
160
+
161
+ db.mycollection.find( { attribs: { color: "blue" } } )
162
+ db.mycollection.find( { attribs: { avail: false } } )
163
+
164
+ Use this kind of indexing strategy for simple attribute lookups rather
165
+ than sorted query results or range queries.
0 commit comments