mongodb - mongo的sort排序问题
过去多啦不再A梦
过去多啦不再A梦 2017-04-28 09:06:02
0
1
801

最近用了mongo,发现个问题,某个集合里,文档对象里有个ctime字段,是MongoDate类型的,我做这样的查询db.find().sort({'ctime':-1}).limit(10),发现是全表扫描了一遍,要想快除非建个{'ctime':-1}的索引

但是用mysql的时候,ctime不建索引,扫描数量也不会很高,因为对数据库底层不是很了解,希望有大神可以指点一下,或者也许是我mongo使用错误,下面是mysql的详情

过去多啦不再A梦
过去多啦不再A梦

reply all(1)
左手右手慢动作

In order not to scan the entire table, indexes are of course necessary. Otherwise, how do we know that the ctime in other data must not be greater than the found pieces of data. As for MySQL, how do you know it has not scanned the entire table? MySQL's data storage is compact, and its scanning speed is much faster than Mongo. Therefore, MySQL has an advantage in the absence of indexes.

One of the advantages of Mongo is its rich query methods, and to demonstrate this feature of Mongo, reasonable and necessary indexes are indispensable.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!