MongoDB/PHP ..如何编写选择查询? [英] MongoDB/PHP.. How to write select queries?
问题描述
如何在mongo db中编写查找查询以选择某些值.例如
How to write find query in mongo db to select certain values. For example
IN MYSQL - SELECT * from things where id=3;
IN Mongo - thingscollection->find(array("_id" => $id))
假设MYSQL查询如下所示,
suppose if the MYSQL query looks like this,
SELECT name,age from things where id=3;
我想知道如何在PHP/MongoDB中编写查找查询以选择特定值?
I am wondering how to write find query in PHP/MongoDB to select specific values?
推荐答案
MySQL: SELECT name,age from things where id=3;
Mongo: $db->things->find(array("id" => 3), array("name" => 1, "age" => 1));
您可能要使用mongo _id
代替自己创建的id
字段.
You may want to use the mongo _id
instead of an own created id
field.
有关php驱动程序的详细信息,请参见: http://php.net/manual /en/mongo.sqltomongo.php 仅将SQL链接到Mongo的另一个很好的链接是 http://rickosborne.org/download/SQL -to-MongoDB.pdf
For more information specifically about the php driver: http://php.net/manual/en/mongo.sqltomongo.php An other good link for just SQL to Mongo is http://rickosborne.org/download/SQL-to-MongoDB.pdf
这篇关于MongoDB/PHP ..如何编写选择查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!