AnyMongo::BSON::OID - A Mongo ObjectId
version 0.03
If no _id field is provided when a document is inserted into the database, an _id field will be added with a new MongoDB::OID as its value.
_id
MongoDB::OID
my $id = $collection->insert({'name' => 'Alice', age => 20});
$id will be a MongoDB::OID that can be used to retreive or update the saved document:
$id
$collection->update({_id => $id}, {'age' => {'$inc' => 1}}); # now Alice is 21
To create a copy of an existing OID, you must set the value attribute in the constructor. For example:
my $id1 = MongoDB::OID->new; my $id2 = MongoDB::OID->new(value => $id1->value);
Now $id1 and $id2 will have the same value.
$id1
$id2
Warning: at the moment, OID generation is not thread safe.
Core documentation on object ids: http://dochub.mongodb.org/core/objectids.
The OID value. A random value will be generated if none exists already. It is a 24-character hexidecimal string (12 bytes).
Its string representation is the 24-character string.
my $hex = $oid->to_string;
Gets the value of this OID as a 24-digit hexidecimal string.
my $date = DateTime->from_epoch(epoch => $id->get_time);
Each OID contains a 4 bytes timestamp from when it was created. This method extracts the timestamp.
my $json = JSON->new; $json->allow_blessed; $json->convert_blessed; $json->encode(MongoDB::OID->new);
Returns a JSON string for this OID. This is compatible with the strict JSON representation used by MongoDB, that is, an OID with the value "012345678901234567890123" will be represented as {"$oid" : "012345678901234567890123"}.
{"$oid" : "012345678901234567890123"}
AnyMongo::ObjectId
Pan Fan(nightsailer) <nightsailer at gmail.com>
Kristina Chodorow <kristina at 10gen.com>
This software is copyright (c) 2010 by Pan Fan(nightsailer).
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install AnyMongo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyMongo
CPAN shell
perl -MCPAN -e shell install AnyMongo
For more information on module installation, please visit the detailed CPAN module installation guide.