{
    "mode": "perldoc",
    "parameter": "MongoDB::IndexView",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/MongoDB%3A%3AIndexView/json",
    "generated": "2026-06-14T07:39:39Z",
    "synopsis": "my $indexes = $collection->indexes;\n# listing indexes\n@names = map { $->{name} } $indexes->list->all;\nmy $result = $indexes->list;\nwhile ( my $indexdoc = $result->next ) {\n# do stuff with each $indexdoc\n}\n# creating indexes\n$name = $indexes->createone( [ x => 1, y => -1 ], { unique => 1 } );\n@names = $indexes->createmany(\n{ keys => [ x => 1, y => -1 ], options => { unique => 1 } },\n{ keys => [ z => 1 ] },\n);\n# dropping indexes\n$indexes->dropone( \"x1y-1\" );\n$indexes->dropall;",
    "sections": {
        "NAME": {
            "content": "MongoDB::IndexView - Index management for a collection\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version v2.2.2\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "my $indexes = $collection->indexes;\n\n# listing indexes\n\n@names = map { $->{name} } $indexes->list->all;\n\nmy $result = $indexes->list;\n\nwhile ( my $indexdoc = $result->next ) {\n# do stuff with each $indexdoc\n}\n\n# creating indexes\n\n$name = $indexes->createone( [ x => 1, y => -1 ], { unique => 1 } );\n\n@names = $indexes->createmany(\n{ keys => [ x => 1, y => -1 ], options => { unique => 1 } },\n{ keys => [ z => 1 ] },\n);\n\n# dropping indexes\n\n$indexes->dropone( \"x1y-1\" );\n\n$indexes->dropall;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This class models the indexes on a MongoDB::Collection so you can create, list or drop them.\n\nFor more on MongoDB indexes, see the MongoDB Manual pages on indexing\n<http://docs.mongodb.org/manual/core/indexes/>\n",
            "subsections": []
        },
        "ATTRIBUTES": {
            "content": "collection\nThe MongoDB::Collection for which indexes are being created or viewed.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "list\n$result = $indexes->list;\n\nwhile ( my $index = $result->next ) {\n...\n}\n\nfor my $index ( $result->all ) {\n...\n}\n\nThis method returns a MongoDB::QueryResult which can be used to retrieve index information\neither one at a time (with \"next\") or all at once (with \"all\").\n\nIf the list can't be retrieved, an exception will be thrown.\n\ncreateone\n$name = $indexes->createone( [ x => 1 ] );\n$name = $indexes->createone( [ x => 1, y => 1 ] );\n$name = $indexes->createone( [ z => 1 ], { unique => 1 } );\n\nThis method takes an ordered index specification document and an optional hash reference of\nindex options and returns the name of the index created. It will throw an exception on error.\n\nThe index specification document is an ordered document (array reference, Tie::IxHash object, or\nsingle-key hash reference) with index keys and direction/type.\n\nSee \"createmany\" for important information about index specifications and options.\n\nThe following additional options are recognized:\n\n*   \"maxTimeMS\" — maximum time in milliseconds before the operation will time out.\n\ncreatemany\n@names = $indexes->createmany(\n{ keys => [ x => 1, y => 1 ] },\n{ keys => [ z => 1 ], options => { unique => 1 } }\n);\n\n@names = $indexes->createmany(\n{ keys => [ x => 1, y => 1 ] },\n{ keys => [ z => 1 ], options => { unique => 1 } }\n\\%globaloptions,\n);\n\nThis method takes a list of index models (given as hash references) and returns a list of index\nnames created. It will throw an exception on error.\n\nIf the last value is a hash reference without a \"keys\" entry, it will be assumed to be a set of\nglobal options. See below for a list of accepted global options.\n\nEach index module is described by the following fields:\n\n*   \"keys\" (required) — an index specification as an ordered document (array reference,\nTie::IxHash object, or single-key hash reference) with index keys and direction/type. See\nbelow for more.\n\n*   \"options\" — an optional hash reference of index options.\n\nThe \"keys\" document needs to be ordered. You are STRONGLY encouraged to get in the habit of\nspecifying index keys with an array reference. Because Perl randomizes the order of hash keys,\nyou may ONLY use a hash reference if it contains a single key.\n\nThe form of the \"keys\" document differs based on the type of index (e.g. single-key, multi-key,\ntext, geospatial, etc.).\n\nFor single and multi-key indexes, the value is \"1\" for an ascending index and \"-1\" for a\ndescending index.\n\n[ name => 1, votes => -1 ] # ascending on name, descending on votes\n\nSee Index Types <http://docs.mongodb.org/manual/core/index-types/> in the MongoDB Manual for\ninstructions for other index types.\n\nThe \"options\" hash reference may have a mix of general-purpose and index-type-specific options.\nSee Index Options\n<http://docs.mongodb.org/manual/reference/method/db.collection.createIndex/#options> in the\nMongoDB Manual for specifics.\n\nSome of the more commonly used options include:\n\n*   \"background\" — when true, index creation won't block but will run in the background; this is\nstrongly recommended to avoid blocking other operations on the database.\n\n*   \"collation\" - a document defining the collation for this operation. See docs for the format\nof the collation document here: <https://docs.mongodb.com/master/reference/collation/>.\n\n*   \"unique\" — enforce uniqueness when true; inserting a duplicate document (or creating one\nwith update modifiers) will raise an error.\n\n*   \"name\" — a name (string) for the index; one will be generated if this is omitted.\n\nGlobal options specified as the last value can contain the following keys:\n\n*   \"maxTimeMS\" — maximum time in milliseconds before the operation will time out.\n\ndropone\n$output = $indexes->dropone( $name );\n$output = $indexes->dropone( $name, \\%options );\n\nThis method takes the name of an index and drops it. It returns the output of the dropIndexes\ncommand (a hash reference) on success or throws a exception if the command errors. However, if\nthe index does not exist, the command output will have the \"ok\" field as a false value, but no\nexception will e thrown.\n\nValid options are:\n\n*   \"maxTimeMS\" — maximum time in milliseconds before the operation will time out.\n\ndropall\n$output = $indexes->dropall;\n$output = $indexes->dropall(\\%options);\n\nThis method drops all indexes (except the one on the \"id\" field). It returns the output of the\ndropIndexes command (a hash reference) on success or throws a exception if the command fails.\n\nValid options are:\n\n*   \"maxTimeMS\" — maximum time in milliseconds before the operation will time out.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "*   David Golden <david@mongodb.com>\n\n*   Rassi <rassi@mongodb.com>\n\n*   Mike Friedman <friedo@friedo.com>\n\n*   Kristina Chodorow <k.chodorow@gmail.com>\n\n*   Florian Ragwitz <rafl@debian.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is Copyright (c) 2020 by MongoDB, Inc.\n\nThis is free software, licensed under:\n\nThe Apache License, Version 2.0, January 2004\n",
            "subsections": []
        }
    },
    "summary": "MongoDB::IndexView - Index management for a collection",
    "flags": [],
    "examples": [],
    "see_also": []
}