Mongodb+php to realize simple deletion, change and check _mongodb

Source: Internet
Author: User
Tags mongoclient mongodb

PHP extensions for MongoDB installed on Windows

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

Find the corresponding PHP version of the DLL file, download php_mongo.dll , placed in the PHP installation directory in the EXT directory, modify php.ini, add an item extension=php_mongo.dll , did not find support for PHP7 DLL

    1. Get Mongoclient object, new out
    2. Get database object db, $MongoClient-> database name by mongoclient the database properties of the object
    3. Gets the collection collection, through the collection property of the DB object, $db-> collection name
    4. Creates a collection that invokes the CreateCollection () method of the DB object,
    5. Call the Collection object's Find () method, query the data, $collection->find ()
    6. Call the update () method of the collection object, update the data, $collection->update ($condition, $data);
    7. Invokes the Insert () method of the collection object, inserting the data, $collection->insert ($data);
 <?php//connect to MongoDB $mongoClient = new Mongoclient ();//Select a database $db = $mongoClient-&G

T;test;

Get collection $collection = $db->users;
Update the document $condition =array ();
$condition ["id"]=1;
$data =array ();
$data [' name ']= ' Wangwu ';
$data [' Age ']= ' 11];

$collection->update ($condition, $data);
Insert Document $data =array ();
$data [' id ']=4;
$data [' name ']= ' haha];
$data [' Age ']= ' 11];

$collection->insert ($data);
Delete Document $condition =array ();
$condition [' id ']=2;

$collection->remove ($condition);
Query document $users = $collection->find (); foreach ($users as $k => $v) {print_r ($v);}?> 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.