Skip to content

Instantly share code, notes, and snippets.

@ccheney
Created October 26, 2012 11:51
Show Gist options
  • Save ccheney/3958350 to your computer and use it in GitHub Desktop.
Save ccheney/3958350 to your computer and use it in GitHub Desktop.
PHP mongodb - list all keys in a collection
$cursor = $collection->find();
$array = iterator_to_array($cursor);
$keys = array();
foreach ($array as $k => $v) {
foreach ($v as $a => $b) {
$keys[] = $a;
}
}
$keys = array_values(array_unique($keys));
// assuming first key is MongoID so skipping it
foreach (array_slice($keys,1) as $key => $value) {
echo "<th>" . $value . "</th>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment