List of Keys Used in MongoDB Collection


/ Published in: PHP
Save to your folder(s)

Takes the collection 'david' and gives a unique array of the keys used.


Copy this code and paste it in your HTML
  1. $m = new Mongo();
  2. $db = $m->test;
  3. $collection = $db->david;
  4. $cursor = $collection->find();
  5. $array = iterator_to_array($cursor);
  6. $keys = array();
  7. foreach ($array as $k=>$v) {
  8. foreach ($v as $a=>$b) {
  9. $keys[] = $a;
  10. }
  11. }
  12. $keys = array_values(array_unique($keys));

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.