For whatever reason the @ symbol throws the php implementation of findOne for a loop.
I think this is the same problem that ejs5 was experiencing but if you are trying to do a findOne on an email address like
$an_array = $col->findOne('email' => 'fred.trotter@example.com');
You will get nothing.
But if you do:
$an_cursor = $col->find('email' => 'fred.trotter@example.com');
$an_array = $an_cursor->getNext();
you will have the same result.
Interestingly I was not able to replicate this problem with the '&' symbol that ejs5 complained about. Perhaps this is a bug being chased down across versions. Hope this helps someone.
-FT
MongoCollection::findOne
(PECL mongo >=0.9.0)
MongoCollection::findOne — Querys this collection, returning a single element
Описание
public array MongoCollection::findOne
([ array $query = array()
[, array $fields = array()
]] )
Параметри
- query
-
The fields for which to search.
- fields
-
Fields of the results to return.
Връщани стойности
Returns record matching the search or NULL.
fred dot trotter at gmail dot com
14-Apr-2012 05:35
ejs5 at g2link dot com
09-Dec-2010 08:30
Special characters seem to be automatically escaped by the Mongo driver.
<?php
$db = $mongo->my_db->wireless_service_providers;
$provider = $db->findOne(array("name" => "AT&T"), array('_id' => 1));
print_r($provider);
?>
if the value is stored as "AT&T" in the document you will get
Array([_id]=>)
but if the value is stored as "AT&T" it will return
Array ( [_id] => MongoId Object ( ) )
dominik at dokdok dot com
30-Sep-2010 11:44
There is also a notation to retrieve all fields, but the specified ones
<?php
$users = $mongo->my_db->users;
$user = $users->findOne(array('username' => 'jwage'), array('password' => 0));
print_r($user);
?>
Will return all fields of the user, but the password field.
