downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

MongoId::__construct> <
[edit] Last updated: Fri, 10 Feb 2012

view this page in

MongoId クラス

(バージョン情報なし。おそらく SVN 版にしか存在しないでしょう)

導入

データベース用に作成した一意な識別子です。オブジェクトをデータベースに挿入するときに _id フィールドを指定しなければ、_id フィールドが追加されてその値は MongoId のインスタンスとなります。 データの中に必然的に一意になるフィールド (ユーザ名やタイムスタンプなど) があるのなら、それを _id フィールドの代わりに使うといいでしょう。 この場合は MongoId で置き換えられることはありません。

MongoId クラスのインスタンスは、 リレーショナルデータベースにおける自動インクリメントの役割を果たします。 つまり、データ自体が必然的にもつ一意なキーがない場合にそれを提供するということです。 自動インクリメントは共有データベースではうまく動作しません。 次の番号を瞬時に見つけることが不可能だからです。 このクラスは、共有環境であっても一意となる値をすばやく生成することができます。

MongoId は 12 バイトです (文字列形式にすると、十六進 24 桁となります)。 最初の 4 バイトはタイムスタンプ、次の 3 バイトはクライアントマシンのホスト名のハッシュ、 その次の 2 バイトはスクリプトを動かしているプロセス ID の下位バイト、 そして最後の 3 バイトはインクリメントする値となります。

MongoId はシリアライズ/アンシリアライズすることができます。 シリアライズした形式は、文字列形式と似ています。

C:7:"MongoId":24:{4af9f23d8ead0e1d32000000}

クラス概要

MongoId {
public string $MongoId->id = NULL ;
/* メソッド */
public MongoId::__construct ([ string $id = NULL ] )
public static string MongoId::getHostname ( void )
public int MongoId::getInc ( void )
public int MongoId::getPID ( void )
public int MongoId::getTimestamp ( void )
public static MongoId MongoId::__set_state ( array $props )
public string MongoId::__toString ( void )
}

フィールド

id
このフィールドには、このオブジェクトの文字列表現が含まれます。

参考

MongoDB コアドキュメントの » id を参照ください。

目次



add a note add a note User Contributed Notes MongoId
alex dot turpin at gmail dot com 11-Jul-2011 06:15
If you need to get the actual ID string, and you try the usual way, PHP will whine because it starts with a dollar sign and it thinks it's a variable. Instead, use this notation:

<?php
    $mongoid
->{'$id'} //Get the $id property of a MongoId object
?>
sararschreiber at gmail dot com 12-Oct-2010 09:23
this is useful for querying for an object by id, given the id's hex:

<?php
$userid
= '4cb4ab6d7addf98506010000';

$theObjId = new MongoId($userid);

$connection = new Mongo();
$db = $connection->thedb->users;

// this will return our matching entry.
$item = $db->findOne(array("_id" => $theObjId));

$connection->close();

?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites