我有一個product_catalog集合,它包含大量的文檔。我們應該用mongodb創建哪些索引來提高性能?
的文件像(文檔結構):
{
"_id": "573c1540c4cebf791315aa0a",
"images": [],
"categories": [
"shirts",
"wedding",
"suits"
],
"publish": "1",
"inventory_management": "none",
"options": [],
"SEO": {
"title": "dummy",
"description": "dfasdfasd",
"keywords": "dummy"
},
"attributes": [],
"features": [],
"files": [],
"seller": "seller_one",
"approve": "approved",
"description": "<span style=\"color: rgb(57, 57, 57); font-family: 'Open Sans'; font-size: 14px; line-height: 21px; text-align: right;\">Description here.</span>",
"name": "dummy",
"alias": "dummy",
"price": 500,
"compare_price": 550,
"collections": [
"collection-2",
"collection-3"
],
"brand": "test_brand",
"sku": "rtrtrt",
"barcode": "12121",
"weight": "12",
"sort_order": 0,
"available": 1,
"uniquesku": [
"rtrtrt"
]
}
我們正在與下面的查詢和排序選項檢索文件。
db.collection('product_catalog').find(query).sort(sort_options).toArray(function(err, records){
// records
})
sort_options : { sort_order: 1, _id: -1 }
Query is like :
1. { publish: '1'}
2. { publish: '1', alias: 'alias_value' }
3. { publish: '1', approve: 'approve_value' }
4. { categories: 'category_value', publish: '1' }
5. { collections: 'collection_value', publish: '1' }
我們應該創建什麼樣的索引來提高讀操作的性能?
發佈的選項有哪些? 0和1?這些文件中有多少百分比是「已發佈:1」。如果它是99%,那麼一個索引就不會超級有用。 –
發佈選項爲0和1.發佈80%的文檔(值:「1」)。我想創建索引,使所有操作變得快速。 – rajeshpanwar
https://docs.mongodb.com/manual/core/index-intersection/#index-intersection-and-sort – rajeshpanwar