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)