NAME
MongoDB::Collection - A Mongo Collection
VERSION
version 0.23
ATTRIBUTES
name
The name of the collection.
full_name
The full_name of the collection, including the namespace of the database it's in.
METHODS
query ($query, \%attrs?)
my $cursor = $collection->query({ i => { '$gt' => 42 } });
my $cursor = $collection->query({ }, { limit => 10, skip => 10 });
my $cursor = $collection->query(
{ location => "Vancouver" },
{ sort_by => { age => 1 } },
);
Executes the given $query and returns a MongoDB::Cursor with the results. A hash reference of attributes may be passed as the second argument.
Valid query attributes are:
- limit
-
Limit the number of results.
- skip
-
Skip a number of results.
- sort_by
-
Order results.
find_one ($query)
my $object = $collection->find_one({ name => 'Resi' });
Executes the given $query and returns the first object matching it.
insert ($object)
my $id = $collection->insert({ name => 'mongo', type => 'database' });
Inserts the given $object into the database and returns it's id value. The id is the _id value specified in the data or a MongoDB::OID.
batch_insert (@array)
my @ids = $collection->batch_insert(({name => "Joe"}, {name => "Fred"}, {name => "Sam"}));
Inserts each of the documents in the array into the database and returns their _ids.
update ($update, $object, $upsert?)
$collection->update($object);
Updates an existing $object in the database.
remove ($query)
$collection->remove({ answer => { '$ne' => 42 } });
Removes all objects matching the given $query from the database.
ensure_index (\@keys, $direction?, $unique?)
$collection->ensure_index([qw/foo bar/]);
Makes sure the given @keys of this collection are indexed. The optional index direction defaults to ascending.
count ($query, $fields)
my $n_objects = $collection->count({ name => 'Bob' });
$bobs_with_zip = $collection->count({ name => 'Bob' }, { zip : 1 });
Counts the number of objects in this collection that match the given $query and contain the given $fields (both parameters optional).
validate
$collection->validate;
Asks the server to validate this collection.
drop_indexes
$collection->drop_indexes;
Removes all indexes from this collection.
drop_index ($index_name)
$collection->drop_index('foo');
Removes an index called $index_name from this collection.
get_indexes
my @indexes = $collection->get_indexes;
Returns a list of all indexes of this collection.
drop
$collection->drop;
Deletes a collection as well as all of its indexes.