/usr/lib/perl5/MongoDB/Indexing.pod is in libmongodb-perl 0.702.1+ds-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | #
# Copyright 2009-2013 10gen, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# PODNAME: MongoDB::Indexing
# ABSTRACT: Indexing collections
__END__
=pod
=head1 NAME
MongoDB::Indexing - Indexing collections
=head1 VERSION
version 0.702.1
=head1 CREATING AN INDEX
Unique and non-unique indexes can be created on collections using
C<MongoDB::Collection::ensure_index>.
For example, to create a non-unique index on C<x>:
$collection->ensure_index({'x' => 1})
To create a unique index on C<y>:
$collection->ensure_index({"y" => 1}, {"unique" => 1});
Multi-key indexes can be created to speed up queries like "sort by name, then by
age." Index direction (1 or -1) is only important for multi-key indexes and
should be the sort order. So, for example, if we want a fast sort by name
ascending and age descending, we'd write:
my $idx = Tie::IxHash->new(name => 1, age => -1);
$collection->ensure_index($idx);
Keep in mind that you should use L<Tie::IxHash> for multi-key indexes to
guarantee the keys will be saved in the correct order.
=head2 Options
The second parameter to C<MongoDB::Collection::ensure_index> specifies index
options. Available options are:
=over
=item C<< unique =E<gt> boolean >>
By default, indexes are not unique. To create a unique index, pass
C<< unique =E<gt> true >>. C<true> can be L<boolean::true> or any other true value.
=item C<< drop_dups => boolean >>
If a unique index is being created on an existing set of data that has duplicate
values, creating the index will fail. To force the index creation by deleting
duplicate values, use this option. Again, any value that evaluates to true will
work.
=item C<safe =E<gt> boolean>
If the update fails and safe is set, this function will return 0. You should
check C<MongoDB::Database::last_error> to find out why the update failed.
=item C<< background =E<gt> boolean >>
Create the index as a background operation.
=item C<< name =E<gt> string >>
Give the index a non-default name. This can be useful if the index contains so
many keys that you get an "index name too long" assertion, or if you just prefer
a more human-readable name.
=back
=head2 See Also
MongoDB documentation on indexing:
L<http://dochub.mongodb.org/core/indexes>.
=head1 GEOSPATIAL INDEXES
Starting in version 1.3.3 of MongoDB, you can create geospatial indexes. These
are useful for querying for "N documents nearest this point" or "documents
within this shape."
To create an index for geospatial queries, use "2d" instead of 1 or -1.
For example, this would create an index on the "location" field:
$coll->ensure_index({"location" => "2d"});
Then, you can query for documents using C<$near>:
my $cursor = $coll->query({"location" => {'$near' => [44, -70]}})->limit(10);
This finds the 10 nearest documents (automatically sorted by distance ascending)
to latitude -70, longitude 44.
Documents must have some sort of pair in the "location" field, although the
database is pretty flexible as to what it will accept:
# valid geospatial locations
$coll->insert({"location" => [44, -70]});
$coll->insert({"location" => {"x" => 44, "y" => -70}});
$coll->insert({"location" => {"foo" => 44, "bar" => -70}});
You can save values in C<(x,y)> or C<(y,x)> order, but you must be consistent.
By default, the geospatial index assumes that points will lie between -180 and
180, for longitude and latitude queries.
=head2 Options
=over
=item C<< min =E<gt> int >>
By default, the geospatial index assumes that points will lie between -180 and
180, for longitude and latitude queries. If you need an alternative minimum
value, you can use this option. This value is exclusive: if you specify
C<< min =E<gt> 0 >>, you cannot save a point with a 0 value coordinate.
=item C<< max =E<gt> int >>
Alternative maximum value, exclusive.
=back
=head2 See Also
MongoDB documentation on geospatial indexes:
L<http://dochub.mongodb.org/core/geo>.
=head1 AUTHORS
=over 4
=item *
Florian Ragwitz <rafl@debian.org>
=item *
Kristina Chodorow <kristina@mongodb.org>
=item *
Mike Friedman <mike.friedman@10gen.com>
=back
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by 10gen, Inc..
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
=cut
|