MONGO first day (MONGO experience)

Source: Internet
Author: User
Tags brew install mongodb install mongodb

I. Installation of mango on Mac OS x

1. Open the terminal window and paste the following script to install Homebrew:

Ruby-e "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. In the terminal Update Brew, open the command line input:

Brew Update

3. Install MongoDB:

Brew Install MongoDB

4. Create the/DATA/DB directory:

Mkdir-p/data/db

5.run MongoDB:

Directly on the command line, enter: MONGO, the default connected time test database, as

    

Second, the basic operation

1. View the currently used database:

Show DBS        // View the database that is currently being created and used

  

2.insert, insert data into the database:

With the database, the next step is the collection, where the collection is named "Students", and the document is in the form of JSON extension (Bson)

    

3.find to view the data that is written in the collection:

Db.students.find (). Pretty ();        // beautifully displays all the data in the students directory

    

"_id": This field is the GUID that the database gives us by default, the purpose is to guarantee the uniqueness of the data

4.update, the first parameter is "condition found" and the second parameter is "updated value"

Db.students.update ({"Name": "Xiaohua"},{"name": "Xiaohua", "age": +, "hobby": ["Swim", "basketball", "Palygame"]})

    

5.remove, delete function

1) Use the Remove () function to remove the data

Db.students.remove ({"Name": "Xiaoming"})        // Delete data under Students collection with name Xiaoming

      

    

2) Delete all data in the collection

Db.students.remove ({})    // Delete all data in the students collection                

    

3) Delete the collection using Drop ()

Db.students.drop ()        // Delete entire students collection                

    

Returns true for delete success

4) Delete the database using the Dropdatabase () function

Db.dropdatabase ()        // Delete the entire current (test) database

        

MONGO first day (MONGO experience)

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.