Vla*_*anu 21 database-design mongodb nosql mongodb-ruby mongodb-indexes
我正在使用MongoDB 1.6.3来存储大集合(300k +记录).我添加了一个复合索引.
db['collection_name'].getIndexes()
[
{
"name" : "_id_",
"ns" : "db_name.event_logs",
"key" : {
"_id" : 1
}
},
{
"key" : {
"updated_at.t" : -1,
"community_id" : 1
},
"ns" : "db_name.event_logs",
"background" : true,
"name" : "updated_at.t_-1_community_id_1"
}
]
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行此代码时:
db['collection_name']
.find({:community_id => 1})
.sort(['updated_at.t', -1])
.skip(@skip)
.limit(@limit)
Run Code Online (Sandbox Code Playgroud)
我正进入(状态:
Mongo :: OperationFailure(没有索引的sort()数据太多.添加索引或指定更小的限制)
我究竟做错了什么?
pin*_*33n 14
尝试添加{community_id: 1, 'updated_at.t': -1}索引.它需要先搜索community_id然后排序.
| 归档时间: |
|
| 查看次数: |
14876 次 |
| 最近记录: |