1MongoDB::OID(3)       User Contributed Perl Documentation      MongoDB::OID(3)
2
3
4

NAME

6       MongoDB::OID - A Mongo ObjectId
7

SYNOPSIS

9       If no "_id" field is provided when a document is inserted into the
10       database, an "_id" field will be added with a new "MongoDB::OID" as its
11       value.
12
13           my $id = $collection->insert({'name' => 'Alice', age => 20});
14
15       $id will be a "MongoDB::OID" that can be used to retreive or update the
16       saved document:
17
18           $collection->update({_id => $id}, {'age' => {'$inc' => 1}});
19           # now Alice is 21
20
21       To create a copy of an existing OID, you must set the value attribute
22       in the constructor.  For example:
23
24           my $id1 = MongoDB::OID->new;
25           my $id2 = MongoDB::OID->new(value => $id1->value);
26
27       Now $id1 and $id2 will have the same value.
28
29       Warning: at the moment, OID generation is not thread safe.
30

SEE ALSO

32       Core documentation on object ids:
33       <http://dochub.mongodb.org/core/objectids>.
34

ATTRIBUTES

36   value
37       The OID value. A random value will be generated if none exists already.
38       It is a 24-character hexidecimal string (12 bytes).
39
40       Its string representation is the 24-character string.
41

METHODS

43   to_string
44           my $hex = $oid->to_string;
45
46       Gets the value of this OID as a 24-digit hexidecimal string.
47
48   get_time
49           my $date = DateTime->from_epoch(epoch => $id->get_time);
50
51       Each OID contains a 4 bytes timestamp from when it was created.  This
52       method extracts the timestamp.
53
54   TO_JSON
55           my $json = JSON->new;
56           $json->allow_blessed;
57           $json->convert_blessed;
58
59           $json->encode(MongoDB::OID->new);
60
61       Returns a JSON string for this OID.  This is compatible with the strict
62       JSON representation used by MongoDB, that is, an OID with the value
63       "012345678901234567890123" will be represented as "{"$oid" :
64       "012345678901234567890123"}".
65

AUTHOR

67         Kristina Chodorow <kristina@mongodb.org>
68
69
70
71perl v5.12.3                      2011-01-19                   MongoDB::OID(3)
Impressum