"root", 'password' => "123456", 'db' => "admin" ]); return $manager; } function mongoQuery($manager){ //查询 $filter = ['age' => ['$gt' => 5]]; $options = [ 'sort' => ['age' => -1] ]; $query = new \MongoDB\Driver\Query($filter,$options); $rows = $manager->executeQuery('admin.user', $query); // 也可选择优先从从库读 foreach ($rows as $r) { print_r($r); } } function mongoInsert($manager,$value){ //2.创建一个BulkWrite对象 $bulk = new \MongoDB\Driver\BulkWrite(); $bulk->insert($value); //3.执行插入 $manager->executeBulkWrite('admin.user', $bulk); } function mongoUpdate($manager,$value,$id){ if (!$id) { return; } $bulk = new \MongoDB\Driver\BulkWrite(); //3.执行插入 $bulk->update( ['_id' => new MongoDB\BSON\ObjectID($id)], ['$set' => $value], // ['multi' => true], ); print_r($manager->executeBulkWrite('admin.user', $bulk)); } function mongoDelete($manager,$id){ if (!$id) { return; } $bulk = new \MongoDB\Driver\BulkWrite(); //3.执行插入 $bulk->delete( ['_id' => new MongoDB\BSON\ObjectID($id)], ); print_r($manager->executeBulkWrite('admin.user', $bulk)); }
标签:mongo,admin,MongoDB,bulk,manager,new,php,id From: https://www.cnblogs.com/xivzhou/p/17429612.html