php本地环境:
C:mongodb4.0in
本地项目www/mongo
本地域名搭建mgo.cn (注意域名配置后还要修改host文件)
如果要mongo操作切换环境php5.6
/-----------------------------Command--------------------------------------------------/
1 //manager mænɪdʒə主教练
2 //bulk baok大部分
3 $manager = new MongoDBDriverManager('mongodb://localhost:27017');
4 $command =new MongoDBDriverCommand([
5 'delete'=>'goods',// collection表名;次参数数组代码参考下方官方
6 'deletes'=> [
7 ['q'=>['price'=>"120"],'limit'=>0]
8 ]
9 ]);
10 $cursor = $manager->executeCommand('ecshop', $command);
11 var_dump($cursor->toArray()[0]);
12
Command资料
用法:https://blog.csdn.net/qq_33028267/article/details/88547137
官方:https://docs.mongodb.com/manual/reference/command/delete/
大神:http://www.php.cn/php-weizijiaocheng-405982.html
$manager = new MongoDBDriverManager('mongodb://localhost:27017'); $command1 = new MongoDBDriverCommand([//查出某一个 "find"=>"goods", "filter"=>["price"=>"130"] ]); $command2= new MongoDBDriverCommand([//查出price字段的 "distinct"=>"goods", "key"=>"price", "query"=>["price"=>"120","price"=>"130"] ]); $command31 =new MongoDBDriverCommand([ //插入 'insert'=>'goods',// collection表名 'documents'=> [ ['_id'=>time(), 'name'=> "栗子", 'price'=> "130" ], ['_id'=>time(), 'name'=> "核桃", 'price'=> "2250" ], ] ]); $command3 =new MongoDBDriverCommand([ //插入 'insert'=>'goods',// collection表名 'documents'=> [ [ 'name'=> "栗子", 'price'=> "130" ], [ 'name'=> "核桃", 'price'=> "2250" ], ] ]);
/------------------BulkWrite------------------------------------------------/
13 $manager = new MongoDBDriverManager("mongodb://localhost:27017");
14 $bulk = new MongoDBDriverBulkWrite();
15 //$bulk->delete([]);
16 //$bulk->insert(['x' => 7, 'name'=>'菜鸟教程', 'url' => 'http://www.runoob.com']);
17 //$bulk->insert(['x' => 2, 'name'=>'
18 //$bulk->insert(['x' => 3, 'name'=>'taobao', 'url' => 'http://www.taobao.com']);
19 //$bulk->update(['x'=>2],['$set'=>['name'=>'谷歌']]);
20 $bulk->insert(['x' => 6, 'title'=>'淘宝', 'url' => 'www.taobao.com']);
21 $manager>executeBulkWrite('mongo.user',$bulk);