PHP operation MONGO Syntax

Source: Internet
Author: User

MongoDB does not support multiple table queries ?


1. Running MONGO Service

Open cmd and enter e: Enter e-drive.

Enter the CD E:\mongdb\bin into the directory.

Enter the Mongod--dbpath E:\mongodb\data//Turn on the MONGO service and save the data in the Information folder.

? do not close cmd, close the MONGO service. ?

2. Operation Grammar

Connecting to a database

<?php$conn = new Mongo ();//Instance $db = $conn->mongo//Select database $coll= $db->user//Select table

Insert

$coll->insert (Array (' ID ' =>48)),//insert int type 48, query for direct ' ID ' =>48$coll->insert (array (' id ' = ' 48 '))// Insert the character type of 48, the time of the query ' id ' = ' 48 '

Delete

$coll->remove ();//delete from User$coll->remove (array (' ID ' =>1));//delete from user where id=1

        select

$coll->find ();// select * from user  $coll->findone ();//select top 1  * from user$coll->find (Array (' ID ' =>1), array (' ID ' =>1, ' name ' =>1);//select id, Name from user where id=1$coll->find (Array (' Name ' =>new mongoregex ('/a/'));// select  * from user where name like  '%a% ' $coll->find (Array (' name ' = >new mongoregex ('/^a/'));//select  * from user where name like   ' a% ' $coll->find (array (' ID ' =>array (' $gt ' =>3))->sort (array (' ID ' =>1))//select *from  user where id>3 order by id asc     $GT is greater than, $lt is less than, Desc is  sort (array (' ID ' =>-1)) $coll->count ();//select count (*)  from user$coll->find ( Array (' $or ' =>array (' id ' =>1;), Array (' name ' = ' B ') ')//select * from user where  Id=1 or name= 'B ' $coll->find ()->limit (5)->skip (0)->sort (array (' ID ' =>1))//select * from user  order by id asc limit 0,5; $db->command (Array (' distinct ' = ' user ', ' key ' = > ' name ')//select distinct * from user

Update

$coll->update (Array ("id" =>3), Array (' $set ' =>array (' id ' =>1));//update user set id=1 where id=3; $coll- >update (Array ("id" =>3), Array (' $inc ' =>array (' id ' =>2));//update user set id=id+2 where id=3;



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.