mongodb+php implementation of simple addition deletion change and check

  • 2020-05-30 21:14:45
  • OfStack

Install the php extension of mongodb on windows

Download address https: / / s3. amazonaws. com/drivers mongodb. org/php/index html

Find the corresponding php version of dll file and download it php_mongo.dll , put it in the ext directory under the php installation directory, modify php.ini, and add 1 item extension=php_mongo.dll , dll support for php7 was not found

Get the MongoClient object, new out Gets the database object db, via the database properties of the MongoClient object, $MongoClient- > The database name Gets the collection collection, via the collection properties of the db object, $db- > A collection of Create the collection, call the createCollection() method of the db object, Call the find() method of the collection object, query the data, $collection- > find() Call the update () method of the collection object to update the data, $collection- > update($condition,$data); Call the insert () method of the collection object, insert the data, $collection- > insert($data);

//  Connect to the mongodb
$mongoClient = new MongoClient();
//  choose 1 A database 
$db = $mongoClient->test;

// For collection 

// Update the document 

// Inserted into the document 
$data['name']=" Ha ha ";

// Delete the document 

// Query the document 
foreach ($users as $k => $v) {

Related articles: