|
One way to work with data that has a high degree of options for queryability is to use the multikey indexing feature where the keys are objects. For example: > x = {
... _id : "abc",
... cost : 33,
... attribs : [
... { color : 'red' },
... { shape : 'rect' },
... { color : 'blue' },
... { avail : true } ]
... };
> db.foo.insert(x);
> db.foo.ensureIndex({attribs:1});
> db.foo.find( { attribs : {color:'blue'} } ); // uses index
> db.foo.find( { attribs : {avail:false} } ); // uses index
In addition to being able to have an unlimited number of attributes types, we can also add new types dynamically. This is mainly useful for simply attribute lookups; the above pattern is not necessary helpful for sorting or certain other query types. See AlsoDiscussion thread MongoDB for a chemical property search engine for a more complex real world example. |

PLEASE POST QUESTIONS IN THE FORUMS: http://groups.google.com/group/mongodb-user. Post tips and clarifications here.
blog comments powered by Disqus