Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Arun kumar
- */
- $mongo = new Mongo();
- $db = $mongo->selectDB("test") or die('no connection');
- //Creating New Database
- //$db = $mongo->Database_Name;
- //Create Collection(table)
- //$db->createCollection("table_name",false);
- //all collection(table) name
- $all_c = $db->getCollectionNames();
- //pr($all_c);
- //use collection
- $user = $db->users;
- $limit_handle = $user->find()->limit(2);
- $result = $user->find();
- foreach ($result as $doc) {
- //pr($doc);
- }
- //pr($result);
- ///count the total record;
- $total_data = $user->count();
- //pr($total_data);
- //Update Records
- $update = array('$set' => array("password" => "A123456"));
- $where = array('_id' => new MongoId("54bfa55fbc76c93399b85ed8"));
- //** $user->update($where,$update);
- //Specify TRUE to limit deletion to just one document. If FALSE or omitted, all documents matching the criteria will be deleted.
- //** $user->remove(array('_id' => new MongoId("54bfa55fbc76c93399b85ed8")), array("justOne" => true));
- ///Insert multiple records into collection
- //save mutiple record
- $doc1 = array("username" => "a2", "password" => rand(101, 200));
- $doc2 = array("username" => "a2", "password" => rand(101, 200));
- $doc3 = array("username" => "a1", "password" => rand(101, 200));
- $doc4 = array("username" => "a", "password" => rand(101, 200));
- /* $user->batchInsert(
- array($doc1, $doc2, $doc3, $doc4),
- array('continueOnError' => true)
- ); */
- ///// Insert into multiple collection
- $people = $db->people;
- $addresses = $db->addresses;
- // Remove all
- $people->remove();
- $addresses->remove();
- $myAddress = array("line 1" => "123 Main Street",
- "line 2" => null,
- "city" => "Springfield",
- "state" => "Vermont",
- "country" => "USA");
- // save the address
- $addresses->insert($myAddress);
- // save a person with a reference to the address
- $me = array("name" => "Arun sharma", "address" => $myAddress['_id']);
- $people->insert($me);
- //die("dfg");
- //$class_methods = get_class_methods('Mongo');
- //pr($class_methods);
- // Insert records int MongoDB.
- //$insert = array('username' => 'demo@sympon.info', 'password' => md5('demo_password'));
- //$user->insert($insert);
- // Find one record
- //$qry = array("user" => $usr_email,"password" => md5($usr_password));
- //$result = $user->findOne($users_find);
- //pr($result);
- //echo "/////////////";
- // Find all record
- $result = $user->find();
- //pr($result);
- function pr($arr = array()) {
- echo "<pre>";
- print_r($arr);
- echo "</pre>";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement