From 7d1ce6a47f068bfffc49ee3fdf83e6c152f8ce28 Mon Sep 17 00:00:00 2001 From: Bob Grabar Date: Wed, 14 Nov 2012 18:41:59 -0500 Subject: [PATCH] DOCS 750 & 757 index faqs --- source/faq/indexes.txt | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/source/faq/indexes.txt b/source/faq/indexes.txt index 77c93b9a565..4529d79ea5f 100644 --- a/source/faq/indexes.txt +++ b/source/faq/indexes.txt @@ -126,3 +126,40 @@ See :ref:`index-selectivity`. If you need to use these, it is often best to make sure that an additional, more selective criterion is part of the query. +Can a multi-key index be used for array matching? +------------------------------------------------- + +A multi-key index can be used to look up an exact array match. It does +so by looking up the first element within the array in the index. + +What is an effective index strategy for attribute lookups? +---------------------------------------------------------- + +For simple attribute lookups, an effective indexing strategy can be to +create a field that contains an array of documents, each document +containing a specific type of attribute an its value. You can then index +that field. + +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 same 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.