|
NAMEMongoDB::IndexView - Index management for a collectionVERSIONversion v2.2.2SYNOPSISmy $indexes = $collection->indexes; # listing indexes @names = map { $_->{name} } $indexes->list->all; my $result = $indexes->list; while ( my $index_doc = $result->next ) { # do stuff with each $index_doc } # creating indexes $name = $indexes->create_one( [ x => 1, y => -1 ], { unique => 1 } ); @names = $indexes->create_many( { keys => [ x => 1, y => -1 ], options => { unique => 1 } }, { keys => [ z => 1 ] }, ); # dropping indexes $indexes->drop_one( "x_1_y_-1" ); $indexes->drop_all; DESCRIPTIONThis class models the indexes on a MongoDB::Collection so you can create, list or drop them.For more on MongoDB indexes, see the MongoDB Manual pages on indexing <http://docs.mongodb.org/manual/core/indexes/> ATTRIBUTEScollectionThe MongoDB::Collection for which indexes are being created or viewed.METHODSlist$result = $indexes->list; while ( my $index = $result->next ) { ... } for my $index ( $result->all ) { ... } This method returns a MongoDB::QueryResult which can be used to retrieve index information either one at a time (with "next") or all at once (with "all"). If the list can't be retrieved, an exception will be thrown. create_one$name = $indexes->create_one( [ x => 1 ] ); $name = $indexes->create_one( [ x => 1, y => 1 ] ); $name = $indexes->create_one( [ z => 1 ], { unique => 1 } ); This method takes an ordered index specification document and an optional hash reference of index options and returns the name of the index created. It will throw an exception on error. The index specification document is an ordered document (array reference, Tie::IxHash object, or single-key hash reference) with index keys and direction/type. See "create_many" for important information about index specifications and options. The following additional options are recognized:
create_many@names = $indexes->create_many( { keys => [ x => 1, y => 1 ] }, { keys => [ z => 1 ], options => { unique => 1 } } ); @names = $indexes->create_many( { keys => [ x => 1, y => 1 ] }, { keys => [ z => 1 ], options => { unique => 1 } } \%global_options, ); This method takes a list of index models (given as hash references) and returns a list of index names created. It will throw an exception on error. If the last value is a hash reference without a "keys" entry, it will be assumed to be a set of global options. See below for a list of accepted global options. Each index module is described by the following fields:
The "keys" document needs to be ordered. You are STRONGLY encouraged to get in the habit of specifying index keys with an array reference. Because Perl randomizes the order of hash keys, you may ONLY use a hash reference if it contains a single key. The form of the "keys" document differs based on the type of index (e.g. single-key, multi-key, text, geospatial, etc.). For single and multi-key indexes, the value is "1" for an ascending index and "-1" for a descending index. [ name => 1, votes => -1 ] # ascending on name, descending on votes See Index Types <http://docs.mongodb.org/manual/core/index-types/> in the MongoDB Manual for instructions for other index types. The "options" hash reference may have a mix of general-purpose and index-type-specific options. See Index Options <http://docs.mongodb.org/manual/reference/method/db.collection.createIndex/#options> in the MongoDB Manual for specifics. Some of the more commonly used options include:
Global options specified as the last value can contain the following keys:
drop_one$output = $indexes->drop_one( $name ); $output = $indexes->drop_one( $name, \%options ); This method takes the name of an index and drops it. It returns the output of the dropIndexes command (a hash reference) on success or throws a exception if the command errors. However, if the index does not exist, the command output will have the "ok" field as a false value, but no exception will e thrown. Valid options are:
drop_all$output = $indexes->drop_all; $output = $indexes->drop_all(\%options); This method drops all indexes (except the one on the "_id" field). It returns the output of the dropIndexes command (a hash reference) on success or throws a exception if the command fails. Valid options are:
AUTHORS
COPYRIGHT AND LICENSEThis software is Copyright (c) 2020 by MongoDB, Inc.This is free software, licensed under: The Apache License, Version 2.0, January 2004
Visit the GSP FreeBSD Man Page Interface. |