日期:2014-05-16  浏览次数:20527 次

使用 Multikeys 模拟大数量的索引

使用 Multikeys 模拟大数量的索引

数据如果有非常多的属性,可以使用multikey索引的特性。
举例

> 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'} } ); // 使用索引
> db.foo.find( { attribs : {avail:false} } );  // 使用索引

这么做也可以动态添加类型。
只能简化属性的查找。上述模式对于排序或者其他类型的查询没什么帮助。

?