Ben kullanmak findOne($query)
üzerine bir Mongo ile konuşmak için PHP kullanıyorum bir db.collection
ben beklediğiniz gibi bir sonuç döndürür. Ama bulmak için () bu komutu değişen hiçbir şey döndürür.
Kabuk, sen db.collection.find kullanırsanız () tüm dokümanları döndürür. Herkes açıklayabilir misiniz neden PHP sürücünün findOne()
aynı sorguyu kullanarak yok iken bile find()
sonuç değil mi?
GÜNCELLEME: İşte kod.
find()
(çalışmıyor):
$db = $connection->selectDB( $database );
$returned_collection = $db->selectCollection( $collection );
$cursor = $returned_collection->find( $query );
);
find()
hata ayıklama çıkışı:
query: array(1) {
["user_id"]=>
string(13) "4d03d13b71676"
}
1292099894 > mongo_wrapper.class.php > returned_collection: events.votes
db: object(MongoDB)#41 (2) {
["w"]=>
int(1)
["wtimeout"]=>
int(10000)
}
cursor: object(MongoCursor)#43 (0) {
}
findOne()
(işleri):
$db = $connection->selectDB( $database );
$returned_collection = $db->selectCollection( $collection );
$cursor = $returned_collection->findOne( $query );
findOne()
hata ayıklama çıkışı:
query: array(1) {
["user_id"]=>
string(13) "4d03d13b71676"
}
1292099906 > mongo_wrapper.class.php > returned_collection: events.votes
db: object(MongoDB)#7862 (2) {
["w"]=>
int(1)
["wtimeout"]=>
int(10000)
}
cursor: array(7) {
["_id"]=>
object(MongoId)#7849 (1) {
["$id"]=>
string(24) "4d03d842d0645afaab4e92f6"
}
["user_id"]=>
string(13) "4d03d13b71676"
["timestamp"]=>
int(1292095809)
["context"]=>
string(3) "ms3"
["uri"]=>
string(120) "http://feeds.marketwatch.com/~r/marketwatch/podcasts/MarketwatchStupidInvestmentOfTheWeek/~3/3H-tMQLS9AA/siotw103009.mp3"
["type"]=>
string(8) "category"
["vote"]=>
int(-1)
}
Her ikisi de bu hata ayıklama kodu kullanabilirsiniz:
if($debug->enabled) {
echo time() . " > mongo_wrapper.class.php > returned_collection: $returned_collection \n";
if($debug->dump) {
echo "db: ";
var_dump( $db );
echo "cursor: ";
var_dump( $cursor );
}
}