php操作mongodb
1.1、connect mongodb
$conn = new Mongo('192.168.63.179'); #连接远程主机,默认端口27017
$db = $conn->test; #选择一个数据库
$collection = $db->abc; #选择一个集合
1.2、 select
$where =
1.$db->users->find(array(), array("a" => 1, "b" => 1));
2.[
'name'=>['$exists'=>1] ,
'age'=>[
'$ne'=>0,
'$lt'=>50,
'$exists'=>1]
] # 存在name字段,存在age字段,且age不等以0,小于50
$field =
1.['name'=>1,'age'=>1];
$rs = $collection->find($where)->fields($field);
foreach ($rs as $key => $value) {
var_dump($value);
}
1.3、 insert
$arr = ['name'=>'wang',age=>19];
$collection->insert($arr);
1.4、 update
$where = ['name'=>'wang'];
$upd = [
'$set'=>['name'=>'wangnan']
]
$collection->update($where,$upd);
1.5、delete
$where = ['age'=>19];
$collection->remove($where);
参考文档:
http://www.cnblogs.com/wubaiqing/archive/2011/09/17/2179870.html
http://www.cnblogs.com/jiqing9006/archive/2012/10/10/2718552.html
http://www.cnblogs.com/egger/archive/2013/06/14/3135847.html
[结合MongoDB开发LBS应用]:http://www.cnblogs.com/egger/archive/2013/06/14/3135847.html "nihao"