Connect to MongoDB:
$MONGOOBJ New Array ( ' connect ' = =true, ' persist ' =true ));
Select a library:
$mongoDB $mongoObj->selectdb ("Wxdata");
Select a collection:
$mongoColletion=$mongoDB->selectcollection ("Apachelog");
To delete a collection:
$mongoColletion->drop ();
Insert document data:
$mongoColletion->insert (array("FirstName" = "Bob", "LastName" and "Jones"));
To modify the updated document data:
$newdata=Array(' $set ' =Array("Address" = "1 Smith Lane"));$mongoColletion->update (Array("FirstName" = "Bob"),$newdata);$mongoColletion-Update (Array("uri" = "/summer_pics"),Array(' $inc ' =Array("page hits" = 1)),Array("Upsert" =true) );$mongoColletion-Update (Array("Name" = "Joe"),Array("username" = "joe312", "createdat" + =NewMongodate ()),Array("Upsert" =true) );$today=Array(' $gt ' =NewMongodate (), ' $lt ' =NewMongodate (Strtotime("+1 Day")));$mongoColletion-Update (Array("Birthday" =$today),Array(' $set ' =Array(' Gift ' =$surprise)),Array("Multiple" =true) );
New Document data:
$obj Array (' x ' = 1); $mongoColletion->save ($obj); $obj [' foo '] = ' bar '; // $obj cannot be inserted again, resulting in duplicate _id error//$mongoColletion->insert ($obj); $mongoColletion->save ($obj);
To remove a document data:
$mongoColletion->remove (arrayarraytrue));
Number of statistical documents:
$mongoColletion,count(array(' Httpstatus ' =>304));
To query a document:
$mongoColletion->findone (array("httpstatus" = 200));
To view document index information:
$mongoColletion->getindexinfo ();
To build a document index:
//Create an index on ' httpstatus ' ascending$mongoColletion->ensureindex (Array(' httpstatus ' = 1));//Create a unique index on ' size '$mongoColletion->ensureindex (Array(' size ' = 1),Array(' unique ' =true));//Create a compound index on ' size ' ascending and ' status ' descending$mongoColletion->ensureindex (Array(' Size ' = 1, ' status ' = 1));//Full-Text indexing$mongoColletion-Ensureindex (Array( ' Title ' = ' text ', ' desc ' = ' text ', ),Array( ' Name ' = ' exampletextindex ', ' weights ' =Array( ' title ' = +, ' desc ' = 30, ) ) );
Close the connection to MongoDB:
$mongoObj->close ();
There are so many functions that you can use from PHP to manipulate MongoDB.