Skip to content

Instantly share code, notes, and snippets.

@Stoffo
Last active September 21, 2015 14:23
Show Gist options
  • Save Stoffo/8d36dc550ac8e4b18be0 to your computer and use it in GitHub Desktop.
Save Stoffo/8d36dc550ac8e4b18be0 to your computer and use it in GitHub Desktop.
Check MongoDB Collection Existance
<?php
/**
* Checks if a Collection already exists.
* Returns true if Collection exists, otherwise it returns false.
*
* @param $collection
*
* @return bool
*/
public function CollectionExists($collection) {
if ($this->db_handle->system->namespaces->findOne(["name" => $this->db.".".$collection]) === null) {
return false;
} else {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment