Advertisement
Guest User

Untitled

a guest
May 24th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * Arun kumar
  5. */
  6.  
  7. $mongo = new Mongo();
  8. $db = $mongo->selectDB("test") or die('no connection');
  9.  
  10. //Creating New Database
  11. //$db = $mongo->Database_Name;
  12. //Create Collection(table)
  13. //$db->createCollection("table_name",false);
  14. //all collection(table) name
  15. $all_c = $db->getCollectionNames();
  16.  
  17. //pr($all_c);
  18. //use collection
  19. $user = $db->users;
  20.  
  21.  
  22. $limit_handle = $user->find()->limit(2);
  23.  
  24. $result = $user->find();
  25.  
  26. foreach ($result as $doc) {
  27. //pr($doc);
  28. }
  29. //pr($result);
  30. ///count the total record;
  31. $total_data = $user->count();
  32. //pr($total_data);
  33. //Update Records
  34.  
  35. $update = array('$set' => array("password" => "A123456"));
  36. $where = array('_id' => new MongoId("54bfa55fbc76c93399b85ed8"));
  37. //** $user->update($where,$update);
  38. //Specify TRUE to limit deletion to just one document. If FALSE or omitted, all documents matching the criteria will be deleted.
  39. //** $user->remove(array('_id' => new MongoId("54bfa55fbc76c93399b85ed8")), array("justOne" => true));
  40. ///Insert multiple records into collection
  41. //save mutiple record
  42. $doc1 = array("username" => "a2", "password" => rand(101, 200));
  43. $doc2 = array("username" => "a2", "password" => rand(101, 200));
  44. $doc3 = array("username" => "a1", "password" => rand(101, 200));
  45. $doc4 = array("username" => "a", "password" => rand(101, 200));
  46.  
  47.  
  48.  
  49. /* $user->batchInsert(
  50. array($doc1, $doc2, $doc3, $doc4),
  51. array('continueOnError' => true)
  52. ); */
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. ///// Insert into multiple collection
  60.  
  61. $people = $db->people;
  62. $addresses = $db->addresses;
  63.  
  64. // Remove all
  65. $people->remove();
  66. $addresses->remove();
  67.  
  68.  
  69.  
  70. $myAddress = array("line 1" => "123 Main Street",
  71. "line 2" => null,
  72. "city" => "Springfield",
  73. "state" => "Vermont",
  74. "country" => "USA");
  75.  
  76. // save the address
  77. $addresses->insert($myAddress);
  78. // save a person with a reference to the address
  79. $me = array("name" => "Arun sharma", "address" => $myAddress['_id']);
  80. $people->insert($me);
  81.  
  82.  
  83.  
  84.  
  85. //die("dfg");
  86. //$class_methods = get_class_methods('Mongo');
  87. //pr($class_methods);
  88. // Insert records int MongoDB.
  89. //$insert = array('username' => 'demo@sympon.info', 'password' => md5('demo_password'));
  90. //$user->insert($insert);
  91. // Find one record
  92. //$qry = array("user" => $usr_email,"password" => md5($usr_password));
  93. //$result = $user->findOne($users_find);
  94. //pr($result);
  95. //echo "/////////////";
  96. // Find all record
  97.  
  98. $result = $user->find();
  99.  
  100. //pr($result);
  101.  
  102. function pr($arr = array()) {
  103. echo "<pre>";
  104. print_r($arr);
  105. echo "</pre>";
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement