Ҫ�鿴������һ�����뵽���ݿ���ĵ������Լ�ʹ�� MongoCollection::findOne() �����Ӽ�������һ�����ĵ��� ���������ֻ���ѯһ�������ʱ������á�
<?php
$connection = new MongoClient();
$collection = $connection->database->collectionName;
$document = $collection->findOne();
var_dump( $document );
?>
�������̻������
array(6) {
["_id"]=>
object(MongoId)#8 (1) {
["$id"]=>
string(24) "4e2995576803fab768000000"
}
["name"]=>
string(7) "MongoDB"
["type"]=>
string(8) "database"
["count"]=>
int(1)
["info"]=>
array(2) {
["x"]=>
int(203)
["y"]=>
int(102)
}
["versions"]=>
array(3) {
[0]=>
string(5) "0.9.7"
[1]=>
string(5) "0.9.8"
[2]=>
string(5) "0.9.9"
}
}
ע�⣺��һ�� _id �ֶα��Զ���ӵ�����ĵ����ˡ� _id �ֶξ��Ǽ��ϵ�"����"�� ��������ĵ���ʱ����û���ֶ�ָ���������ͻ��Զ��������һ����
�������������ĵ������� _id �ֶΣ���ô���ڼ����б�����Ψһ�ġ� ����һ�����ӣ�
<?php
$connection = new MongoClient();
$db = $connection->database;
$db->foo->insert(array("_id" => 1));
// this will throw an exception
$db->foo->insert(array("_id" => 1));
// this is fine, as it is a different collection
$db->bar->insert(array("_id" => 1));
?>
Ĭ������ʱ���������ڷ�����ͨ����д������أ���ע��"ͨ��"������������������������������ĵ���һ���������д�룬�Ⲣ����ζ�������Ѿ�д����̣��������ͨ�����ڶ���������Ϊ array("w" => 0) ���ı�Ĭ����Ϊ����ʱ��IJ���������������أ����Ҳ����׳� _id �ظ����쳣��
MongoCollection::findOne() �������ĵ����жԲ�ѯ����ϸ˵����
ΨһID����Ϣ�鿴 MongoId
д�� ���ָ���ϸ��˵����д����, Write Concerns �½����������һЩд������ѡ�