[DOCS-750] Index FAQ: Arbitrary Attributes Created: 14/Nov/12  Updated: 15/Nov/12  Resolved: 15/Nov/12

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Sam Kleinman (Inactive) Assignee: Bob Grabar
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 11 years, 13 weeks, 6 days ago

 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.



 Comments   
Comment by auto [ 15/Nov/12 ]

Author:

{u'date': u'2012-11-15T18:46:25Z', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}

Message: DOCS-750 and DOCS-757: avoid single document fields, and correction about array matches and indexes
Branch: master
https://github.com/mongodb/docs/commit/564d04049f835cf19375428c581b83b036e3309c

Comment by Scott Hernandez (Inactive) [ 15/Nov/12 ]

Single field docs:

[{key:value},...]

Key/Value docs:

[{k:<key>, v:<value>},...]

We should mostly not document the first way, and esp. not without explaining the usage and limitations.

Comment by Sam Kleinman (Inactive) [ 15/Nov/12 ]

scotthernandez we can add another item to the FAQ, if you could give us a little more to go on, This was pulled in, in an attempt to not loose information in the conversion from the wiki. I'm happy to delete it if you don't think it's worth including.

Comment by auto [ 15/Nov/12 ]

Author:

{u'date': u'2012-11-15T18:01:00Z', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}

Message: merge: DOCS-750 and DOCS-757
Branch: master
https://github.com/mongodb/docs/commit/d299e9905bc2d4d01252dc86a45ea2285cca5e3d

Comment by Bob Grabar [ 14/Nov/12 ]

This change has been committed:
https://github.com/bgrabar/docs-mongodb/commit/7d1ce6a47f068bfffc49ee3fdf83e6c152f8ce28

Comment by Bob Grabar [ 14/Nov/12 ]

Scott, by key/value you mean an array like the "attrib" array above, right? By single fields, do you mean something like this:

{ attribute : [red, rectangle, true] }
Comment by Scott Hernandez (Inactive) [ 14/Nov/12 ]

Generally better to use key/value docs rather than single fields. Might want to discuss the differences...

Generated at Thu Feb 08 07:39:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.