<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/mongodb.bson.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'class.mongodb-bson-objectid.php',
    1 => 'MongoDB\\BSON\\ObjectId',
    2 => 'The MongoDB\\BSON\\ObjectId class',
  ),
  'up' => 
  array (
    0 => 'mongodb.bson.php',
    1 => 'MongoDB\\BSON',
  ),
  'prev' => 
  array (
    0 => 'mongodb-bson-minkey.jsonserialize.php',
    1 => 'MongoDB\\BSON\\MinKey::jsonSerialize',
  ),
  'next' => 
  array (
    0 => 'mongodb-bson-objectid.construct.php',
    1 => 'MongoDB\\BSON\\ObjectId::__construct',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mongodb/bson/objectid.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.mongodb-bson-objectid.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.mongodb-bson-objectid" class="reference">

 <h1 class="title">The MongoDB\BSON\ObjectId class</h1>
 

 <div class="partintro"><p class="verinfo">(mongodb &gt;=1.0.0)</p>


  <div class="section" id="mongodb-bson-objectid.intro">
   <h2 class="title">简介</h2>
   <p class="simpara">
    BSON type for an
    <a href="https://www.mongodb.com/docs/manual/reference/bson-types/#objectid" class="link external">&raquo;&nbsp;ObjectId</a>. The
    value consists of 12 bytes, where the first four bytes are a timestamp
    that reflect the ObjectId&#039;s creation. Specifically, the value consists of:
   </p>
   <ul class="itemizedlist">
    <li class="listitem"><span class="simpara">a 4-byte value representing the seconds since the Unix epoch,</span></li>
    <li class="listitem"><span class="simpara">a 5-byte random number unique to a machine and process, and</span></li>
    <li class="listitem"><span class="simpara">a 3-byte counter, starting with a random value.</span></li>
   </ul>
   <p class="simpara">
    In MongoDB, each document stored in a collection requires a unique
    <code class="literal">_id</code> field that acts as a primary key. If an inserted
    document omits the <code class="literal">_id</code> field, the extension automatically
    generates an ObjectId for the <code class="literal">_id</code> field.
   </p>
   <p class="simpara">
    Using ObjectIds for the <code class="literal">_id</code> field provides the following
    additional benefits:
   </p>
   <ul class="itemizedlist">
    <li class="listitem"><span class="simpara">The creation time of the ObjectId may be accessed using the <span class="methodname"><a href="mongodb-bson-objectid.gettimestamp.php" class="methodname">MongoDB\BSON\ObjectId::getTimestamp()</a></span> method.</span></li>
    <li class="listitem"><span class="simpara">Sorting on an <code class="literal">_id</code> field that stores ObjectId values is roughly equivalent to sorting by creation time.</span></li>
   </ul>
  </div>


  <div class="section" id="mongodb-bson-objectid.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <span class="ooclass"><strong class="classname"></strong></span>


    <div class="classsynopsisinfo">
     <span class="modifier">final</span>
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">MongoDB\BSON\ObjectId</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <a href="class.mongodb-bson-objectidinterface.php" class="interfacename">MongoDB\BSON\ObjectIdInterface</a></span><span class="oointerface">,  <a href="class.mongodb-bson-type.php" class="interfacename">MongoDB\BSON\Type</a></span><span class="oointerface">,  <a href="class.jsonserializable.php" class="interfacename">JsonSerializable</a></span><span class="oointerface">,  <a href="class.stringable.php" class="interfacename">Stringable</a></span> {</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-objectid.construct.php" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span> <code class="parameter">$id</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>)</div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-objectid.gettimestamp.php" class="methodname">getTimestamp</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-objectid.jsonserialize.php" class="methodname">jsonSerialize</a></span>(): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-bson-objectid.tostring.php" class="methodname">__toString</a></span>(): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

   }</div>


  </div>

  <div class="section">
   <h2 class="title">更新日志</h2>
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      
       <tr>
        <td>PECL mongodb 2.0.0</td>
        <td>
         <p class="para">
          此类不再实现 <span class="interfacename"><a href="class.serializable.php" class="interfacename">Serializable</a></span> 接口。
         </p>
        </td>
       </tr>


      <tr>
       <td>PECL mongodb 1.12.0</td>
       <td>
        Implements <span class="interfacename"><a href="class.stringable.php" class="interfacename">Stringable</a></span> for PHP 8.0+.
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.3.0</td>
       <td>
        <span class="simpara">
         Renamed from <code class="literal">MongoDB\BSON\ObjectID</code> to
         <code class="literal">MongoDB\BSON\ObjectId</code>.
        </span>
        <span class="simpara">
         Implements <span class="interfacename"><a href="class.mongodb-bson-objectidinterface.php" class="interfacename">MongoDB\BSON\ObjectIdInterface</a></span>.
        </span>
       </td>
      </tr>

      <tr>
       <td>PECL mongodb 1.2.0</td>
       <td>
        Implements <span class="interfacename"><a href="class.serializable.php" class="interfacename">Serializable</a></span> and
        <span class="interfacename"><a href="class.jsonserializable.php" class="interfacename">JsonSerializable</a></span>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </div>

 </div>

 




























<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="mongodb-bson-objectid.construct.php">MongoDB\BSON\ObjectId::__construct</a> — Construct a new ObjectId</li><li><a href="mongodb-bson-objectid.gettimestamp.php">MongoDB\BSON\ObjectId::getTimestamp</a> — Returns the timestamp component of this ObjectId</li><li><a href="mongodb-bson-objectid.jsonserialize.php">MongoDB\BSON\ObjectId::jsonSerialize</a> — Returns a representation that can be converted to JSON</li><li><a href="mongodb-bson-objectid.tostring.php">MongoDB\BSON\ObjectId::__toString</a> — Returns the hexidecimal representation of this ObjectId</li></ul>
</div>
<?php manual_footer($setup); ?>