读书人

运用 Multikeys 模拟大数量的索引

发布时间: 2012-07-26 12:01:08 作者: rapoo

使用 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} } );  // 使用索引

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

?

读书人网 >其他数据库

热点推荐