Connect Azure's Documentdb PaaS via PHP's MongoDB driver

Source: Internet
Author: User


Azure's Documentdb is a nosql type of database. It can also be compatible with today's popular MongoDB, with MongoDB's driver directly connected to Azure's ducumentdb.

Currently, DOCUMENTDB is officially commercially available on Azure, and the MongoDB-compatible version is still in the preview phase.

This article will show you how to create and connect documentdb through the driver of the PHP MongoDB.

Create a documentdb on the Azure management interface:

1 click the "+" sign in the upper-left corner of the portal, then enter DOCUMENTDB, return:

2 Select Ducumentdb-protocol Support for MongoDB (preview):

The option to accept preview appears in the middle, as accepted.

3 Click Create after the following dialog box appears, fill in the content as required:

4 minutes later you can see that the created Documentdb is online:

5 Creating DB and collection:

Click on the Created Documentdb and select Add Database in the overview:

Enter database's name:

Once the creation is successful, click this database:

After entering the database, click Add Collection:

In the dialog box that appears, type:

According to their own needs, select the corresponding performance services.

In a few seconds, collection was created.

6 record link string, in Documentdb there is an option called connection string, click, and Copy connection string:

Two install PHP MONGO on CentOS driver

1 creating repo for Epel and MONGO

Under/ETC/YUM.REPOS.D, add two files:

epel.repo[epel]name=epelbaseurl=$basearch enabled=1gpgcheck=0
mongo.repo[mongodb-org-2.6]name 2.6 repositorybaseurl= gpgcheck=0Enabled=1

2 Yum Install the appropriate software:

Yum Install httpd-yyuminstall php-yyumInstall Php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath LIBMCR Ypt-yyuminstall openssl-devel-yyuminstall -y mongodb-orgyum install Php-pecl-mongo

Php-pecl-mongo can also be installed by hand:

Download MongoDB Extensions

 wget  http://  tar  vxf mongodb-8  .tgz  MV  mongodb-1.1 . 8 /usr/local/php- /configure--with-php-config=/usr/bin/php-configmake  && make  install  echo   '  

However, this installation requires attention to the compatibility of each version.

3 establishing a connection to Documentdb in PHP

Create index.php in/var/www/html

<?PHP//phpinfo ();  $mongo=NewMONGO (' Mongodb://hipomdb01:[email protected]:10250/?ssl=true '); Var_dump($mongo); Echo"<br>"; $mongodb=$mongo-MyDB; Var_dump($mongodb); Echo"<br>"; $collection=$mongodb->selectcollection (' Stu '); Var_dump($collection);  for($i= 0;$i<=200;$i++){    $array=Array(' _id ' =$i+1, ' sn ' = =$i+1, ' name ' = ' Zhang San ' +$i, ' gender ' = ' male ', ' age ' =>8); $collection->insert ($array); }  Echo"<br>"; Echo' Count: '.$collection-Count()." <br> ";?>

Browse through a browser and see the following:

Indicates that the data has been inserted successfully.

Connect Azure's Documentdb PaaS via PHP's MongoDB driver

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: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: