Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Die $indexStats Aggregationsphase gibt Nutzungsstatistiken für jeden Index in der Auflistung zurück. Diese Phase ist nützlich, um die Indexleistung zu analysieren, nicht verwendete Indizes zu identifizieren und die Abfrageleistung zu optimieren.
Syntax
{
$indexStats: {}
}
Die Parameter
Die $indexStats Phase akzeptiert keine Parameter.
Examples
Betrachten Sie dieses Beispieldokument aus der Stores-Sammlung.
{
"_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4",
"name": "First Up Consultants | Beverage Shop - Satterfieldmouth",
"location": {
"lat": -89.2384,
"lon": -46.4012
},
"staff": {
"totalStaff": {
"fullTime": 8,
"partTime": 20
}
},
"sales": {
"totalSales": 75670,
"salesByCategory": [
{
"categoryName": "Wine Accessories",
"totalSales": 34440
},
{
"categoryName": "Bitters",
"totalSales": 39496
},
{
"categoryName": "Rum",
"totalSales": 1734
}
]
},
"promotionEvents": [
{
"eventName": "Unbeatable Bargain Bash",
"promotionalDates": {
"startDate": {
"Year": 2024,
"Month": 6,
"Day": 23
},
"endDate": {
"Year": 2024,
"Month": 7,
"Day": 2
}
},
"discounts": [
{
"categoryName": "Whiskey",
"discountPercentage": 7
},
{
"categoryName": "Bitters",
"discountPercentage": 15
},
{
"categoryName": "Brandy",
"discountPercentage": 8
},
{
"categoryName": "Sports Drinks",
"discountPercentage": 22
},
{
"categoryName": "Vodka",
"discountPercentage": 19
}
]
},
{
"eventName": "Steal of a Deal Days",
"promotionalDates": {
"startDate": {
"Year": 2024,
"Month": 9,
"Day": 21
},
"endDate": {
"Year": 2024,
"Month": 9,
"Day": 29
}
},
"discounts": [
{
"categoryName": "Organic Wine",
"discountPercentage": 19
},
{
"categoryName": "White Wine",
"discountPercentage": 20
},
{
"categoryName": "Sparkling Wine",
"discountPercentage": 19
},
{
"categoryName": "Whiskey",
"discountPercentage": 17
},
{
"categoryName": "Vodka",
"discountPercentage": 23
}
]
}
]
}
Beispiel 1 : Abrufen von Indexstatistiken
Diese Abfrage ruft Nutzungsstatistiken für alle Indizes in der Speicherauflistung ab.
db.stores.aggregate([
{ $indexStats: {} }
])
Die Abfrage gibt Statistiken für jeden Index einschließlich Zugriffsmustern und Nutzungshäufigkeit zurück.
[
{
"name": "_id_",
"key": { "_id": 1 },
"accesses": { "ops": 41675, "since": "2025-06-07T13:51:41.231Z" },
"spec": { "v": 2, "key": { "_id": 1 }, "name": "_id_" }
},
{
"name": "location_2dsphere",
"key": { "location": "2dsphere" },
"accesses": { "ops": 0, "since": "2025-06-07T13:51:41.231Z" },
"spec": {
"v": 2,
"key": { "location": "2dsphere" },
"name": "location_2dsphere",
"2dsphereIndexVersion": 3
}
},
{
"name": "name_text_sales.salesByCategory.categoryName_text_promotionEvents.eventName_text_promotionEvents.discounts.categoryName_text",
"key": {
"name": "text",
"sales.salesByCategory.categoryName": "text",
"promotionEvents.eventName": "text",
"promotionEvents.discounts.categoryName": "text"
},
"accesses": { "ops": 8, "since": "2025-06-07T13:51:41.231Z" },
"spec": {
"v": 2,
"key": {
"name": "text",
"sales.salesByCategory.categoryName": "text",
"promotionEvents.eventName": "text",
"promotionEvents.discounts.categoryName": "text"
},
"name": "name_text_sales.salesByCategory.categoryName_text_promotionEvents.eventName_text_promotionEvents.discounts.categoryName_text"
}
}
]