Linux: Installing and using MONGO

Source: Internet
Author: User
Tags mongodb tutorial mongo shell

1. Download MONGO: Curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz

2. Unzip: tar -zxvf mongodb-linux-x86_64-3.0. 6.tgz

< Span class= "PLN" >3. Renaming: MV mongodb-linux-x86_64-3.0.6//usr/local/mongodb

< Span class= "PLN" >4. Add environment variable:   export=<mongodb-install -directory>/bin:< Span class= "PLN" > $PATH  , Source/etc/profile re-entry into force.

5. Create a new database directory: mkdir -p /data/db,/data/db is the default startup database path for MongoDB

6. Start MONGODB:CD <mongodb-Install-directory>/bin into the bin directory, run:./mongod

7. Open a new command window, also into the bin directory, run./mongo into the MONGO shell

8. Syntax:

< Span class= "PLN" >< Span class= "pun" > New database Runoob:use runoob, switch to Database Runoob, the next time the data is written: db. runoob.insert ({"Name": " Insert Data "}" to create the database automatically.

Delete the database runoob:use runoob, switch to the database you want to delete, and then run: db. Dropdatabase()

Update data:db.runoob.update ({' Conrolname ': ' Value '},{$set: {' updatetitle ': ' Updatevalue '}}), this statement only modifies the first found document , if you want to modify more than one document, you need to add the following settings {Multi:true}

  Save () Method: Db.runoob.save ({"_id": "Value", "title": "Value"}), overriding for all values.

Delete data: Db.runoob.deleteMany ({"title": "Value"}), delete multiple data, Db.runoob.deleteOne ({"title": "Value"}), delete one piece of data

Query data:db. Runoob. Find(). Pretty(), FindOne () returns a single piece of data.

Db.runoob.find ({$or: [{"Title1": "Value1"},{"title2": "Value2"}]}). Pretty (), conditional or query.

Db.col.find ({"likes": {$gt: $}, $or: [{"By": "Rookie Tutorial"},{"title": "MongoDB Tutorial"}]}). Pretty, where likes>50 and (by = ' Rookie Tutorial ' ' OR title = ' MongoDB tutorial ') '

Linux: Installing and using MONGO

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.