|
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. |

IF YOU HAVE A QUESTION, POST IT TO THE USER GROUP.
These pages are fine for comments, but for questions, your best bet will always be the MongoDB User Group. blog comments powered by Disqus