This article mainly introduces the PHP operation MongoDB Concise tutorial, including connection, add, modify, delete, query and so on, the need for friends can refer to the next
The code is as follows://Connect Localhost:27017$conn = new Mongo (); Connect the remote host default port $conn = new Mongo (' test.com '); Connect remote host 22011 port $conn = new Mongo (' test.com:22011 '); MongoDB has user name password $conn = new Mongo ("Mongodb://${username}:${password} @localhost")//mongodb username password and specify database Blog$conn = new Mongo ("Mongodb://${username}:${password} @localhost/blog"); Multiple servers $conn = new Mongo ("mongodb://localhost:27017,localhost:27018");//Select Database Blog$db = $conn->blog;// Set result set (table name: users) $collection = $db->users;//New $user = Array (' name ' = ' Caleng ', ' email ' = ' admin#admin.com '); $ Collection->insert ($user);//Modify $newdata = Array (' $set ' = = Array ("email" = "test@test.com"); $collection- >update (Array ("name" = "Caleng"), $newdata),//delete $collection->remove (' name ' = ' Caleng '), Array (" Justone "= True)"//Find $cursor = $collection->find (); Var_dump ($cursor);//Find a $user = $collection->findone ( Array (' name ' = ' Caleng '), array (' email ')); Var_dump ($user);//Close Database $conn->close ();
http://www.bkjia.com/PHPjc/745941.html www.bkjia.com true http://www.bkjia.com/PHPjc/745941.html techarticle This article mainly introduces the PHP operation MongoDB Concise tutorial, including connection, add, modify, delete, query and so on, the need for friends can refer to the following code://Connect Localhost:27017$conn ...