Guest User

Untitled

a guest
Feb 19th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. <?php
  2. try {
  3. $mongo = new Mongo(); // default host:port
  4. $db = $mongo->example;
  5. $collection = $db->test;
  6. $collection->drop();
  7.  
  8. $document = array( '_id' => 'gates',
  9. 'name' => 'Gaëtan Voyer-Perrault',
  10. 'friends' => array('bernie', 'alvin'),
  11. 'followers' => 18,
  12. 'contact' => array( 'twitter' => '@gatesvp',
  13. 'email' => 'gates@10gen.com')
  14. );
  15. $collection->insert($document);
  16.  
  17. $query = array( '_id' => 'gates');
  18. $fields = array( '_id' => 0, 'name' => 1, 'friends' => 1);
  19. $result = $collection->findOne($query, $fields);
  20.  
  21. print_r($result);
  22. }
  23. catch(Exception $e) {
  24. print($e->getMessage());
  25. }
  26. ?>
Add Comment
Please, Sign In to add comment