0
在mongo中,當創建一個索引時,我試圖弄清楚下面的查詢是否有索引a)category_ids和status,或者b)category_ids,status和name ???如何在WHERE和ORDER查詢中的mongodb中創建索引?
Source.where(category_ids: [1,2,3], status: Status::ACTIVE).order_by(:name) # ((Ruby/Mongoid code))
本質上,我試圖找出索引是否應該包括ORDER_BY列?或只有WHERE子句?我在哪裏可以讀到更多關於此的內容?
是的,這個特定查詢的索引對索引中的查詢字段和排序字段都會更有利。這裏有很多好的鏈接:http://docs.mongodb.org/manual/applications/indexes/ http://docs.mongodb.org/manual/faq/indexes/#how-do-you-determine-what-fields -to-index http://jasonwilder.com/blog/2012/02/08/optimizing-mongodb-indexes/ http://stackoverflow.com/questions/10329104/why-does-direction-of-index-matter- in-mongodb http://www.slideshare.net/kbanker/mongo-indexoptimizationprimer來自快速谷歌搜索 – Sammaye 2013-02-11 15:03:16