The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MongoDB::Collection - A Mongo Collection

VERSION

version 0.01

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)

    my $cursor = $collection->query({ i => { '$gt' => 42 } });

Executes the given $query and returns a MongoDB::Cursor with the 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 its MongoDB::OID.

update ($update, $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?)

    $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)

    my $n_objects = $collection->count({ name => 'Bob' });

Counts the number of objects in this collection that match the given $query.

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.

AUTHOR

  Florian Ragwitz <rafl@debian.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2009 by 10Gen.

This is free software, licensed under:

  The Apache License, Version 2.0, January 2004