GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MONGODB::OID (3)

.ds Aq ’

NAME

MongoDB::OID - A Mongo Object ID

CONTENTS

VERSION

version v1.2.3

SYNOPSIS

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.



    my $id = $collection->insert({name => Alice, age => 20});



$id will be a MongoDB::OID that can be used to retrieve or update the saved document:



    $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);
    my $id3 = MongoDB::OID->new($id1->value);
    my $id4 = MongoDB::OID->new($id1);



Now $id1, $id2, $id3 and $id4 will have the same value.

OID generation is thread safe.

ATTRIBUTES

    value

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.

METHODS

    to_string



    my $hex = $oid->to_string;



Gets the value of this OID as a 24-digit hexidecimal string.

    get_time



    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.

    TO_JSON



    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"}.

SEE ALSO

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

AUTHORS

o David Golden <david@mongodb.com>
o Mike Friedman <friedo@friedo.com>
o Kristina Chodorow <k.chodorow@gmail.com>
o Florian Ragwitz <rafl@debian.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2016 by MongoDB, Inc..

This is free software, licensed under:



  The Apache License, Version 2.0, January 2004



Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MONGODB::OID (3) 2016-03-08

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.