Drops a collection
public dropCollection ( MongoCollection | string $coll ) : array | ||
$coll | MongoCollection | string | MongoCollection or name of collection to drop. |
리턴 | array | Returns the database response. |
public function tearDown() { $this->database->dropCollection('testCollection'); $this->database->drop(); if (Mongo::getInstance()) { Mongo::getInstance()->destroy(); } }
public function testDropCollection2() { $ns = $this->object->selectCollection('system.namespaces'); $this->object->x->insert(array("foo"=>"bar")); $this->assertNotNull($ns->findOne(array('name'=> new MongoRegex('/.x$/')))); $this->object->dropCollection('x'); $this->assertEquals($ns->findOne(array('name'=> new MongoRegex('/.x$/'))), null); $this->object->x->insert(array("foo"=>"bar")); $this->assertNotNull($ns->findOne(array('name'=> new MongoRegex('/.x$/')))); $this->object->dropCollection($this->object->x); $this->assertEquals($ns->findOne(array('name'=> new MongoRegex('/.x$/'))), null); $mem = memory_get_usage(true); for ($i=0; $i<1000; $i++) { $this->object->dropCollection("form"); } $this->assertEquals($mem, memory_get_usage(true)); $mem = memory_get_usage(true); for ($i=0; $i<1000; $i++) { $this->object->dropCollection($this->object->form); } $this->assertEquals($mem, memory_get_usage(true)); }
/** * Return an array of stored tags * * @return array array of stored tags (string) */ public function getTags() { $cmd['mapreduce'] = $this->_options['collection']; $cmd['map'] = 'function(){ this.t.forEach( function(z){ emit( z , { count : 1 } ); } ); };'; $cmd['reduce'] = 'function( key , values ){ var total = 0; for ( var i=0; i<values.length; i++ ) total += values[i].count; return { count : total }; };'; $cmd['out'] = array('replace' => 'getTagsCollection'); $res2 = $this->_db->command($cmd); $res3 = $this->_db->selectCollection('getTagsCollection')->find(); $res = array(); foreach ($res3 as $key => $val) { $res[] = $key; } $this->_db->dropCollection($res2['result']); return $res; }
/** * Delete the database with all documents, it will be recreated on * next access. * * @return void */ public function resetStorage() { $collectioNames = $this->database->listCollections(); foreach ($collectioNames as $collectionName) { $this->database->dropCollection($collectionName); } }
/** * Wrapper method for MongoDB::dropCollection(). * * @see http://php.net/manual/en/mongodb.dropcollection.php * @param string $coll * @return array */ public function dropCollection($coll) { return $this->mongoDB->dropCollection($coll); }
/** drop collection **/ public function doRemoveCollection() { $this->db = x("db"); $this->collection = xn("collection"); $db = new MongoDB($this->_mongo, $this->db); $db->dropCollection($this->collection); $this->display(); }
protected function _call($command, array $arguments = array(), array $values = NULL) { $this->_connected or $this->connect(); extract($arguments); $_bm_name = isset($collection_name) ? $collection_name . '.' . $command : $command; if (isset($collection_name)) { $c = $this->_db->selectCollection($collection_name); } switch ($command) { case 'ensure_index': $r = $c->ensureIndex($keys, $options); break; case 'create_collection': $r = $this->_db->createCollection($name, $capped, $size, $max); break; case 'drop_collection': $r = $this->_db->dropCollection($name); break; case 'command': $r = $this->_db->command($values); break; case 'execute': $r = $this->_db->execute($code, $args); break; case 'batch_insert': $r = $c->batchInsert($values); break; case 'count': $r = $c->count($query); break; case 'find_one': $r = $c->findOne($query, $fields); break; case 'find': $r = $c->find($query, $fields); break; case 'group': $r = $c->group($keys, $initial, $reduce, $condition); break; case 'update': $r = $c->update($criteria, $values, $options); break; case 'insert': $r = $c->insert($values, $options); break; case 'remove': $r = $c->remove($criteria, $options); break; case 'save': $r = $c->save($values, $options); break; case 'get_file': $r = $this->gridFS()->findOne($criteria); break; case 'get_files': $r = $this->gridFS()->find($query, $fields); break; case 'set_file_bytes': $r = $this->gridFS()->storeBytes($bytes, $extra, $options); break; case 'set_file': $r = $this->gridFS()->storeFile($filename, $extra, $options); break; case 'remove_file': $r = $this->gridFS()->remove($criteria, $options); break; } if (isset($_bm)) { Profiler::stop($_bm); } return $r; }