未建立索引排序是出现问题

> db.locations.find().sort({date:-1})
error: {
    "$err" : "too much data for sort() with no index.  add an index or specify a smaller limit",
    "code" : 10128
}

查看记录总数

> db.locations.count()
253953

建立和查看索引

> db.locations.ensureIndex({"date":1})

> db.locations.getIndexes()
[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
        "ns" : "lmiot.locations",
        "name" : "_id_"
    },
    {
        "v" : 1,
        "key" : {
            "date" : 1
        },
        "ns" : "lmiot.locations",
        "name" : "date_1"
    }
]

查看所有索引

> db.system.indexes.find()

[ 编辑 | 历史 ]
最近由“jilili”在“2015-05-27 00:42:14”修改