In order to facilitate the practice, we will follow the "8-day learning MongoDB" series of actual operations and make learning diary records.
I. Download
Go to the official MongoDB download page, which has 32-bit and 64-bit versions. Pay attention to the following:
- According to industry rules, the even number is "stable version" (for example, 1.6.x, 1.8.x), and the odd number is "development version" (for example, 1.7.x, 1.9.x ), I believe everyone knows the difference between the two versions.
- 32-bit MongoDB can only store up to 2 GB of data, with no limit on 64-bit data.
I chose the 64-bit version 2.0.4. Decompress the package to drive C and change the folder name to MongoDB.
Ii. Start
- Before startup, add a sub-directory DB under the c: \ MongoDB directory to store MongoDB data.
- In the command line, enter the followingCode
CodeCd c: \ MongoDB \ binmongod -- dbpath = c: \ MongoDB \ DB
- Finally, check whether it is enabled successfully. The information shows that MongoDB uses port 27017. Then, type "http: // localhost: 27017/" in the browser, mongoDB tells us that you can use http mode to view MongoDB Management Information (http: // localhost: 27017/) on add 1000 /)
III. Basic operations
Next we will try to add, delete, query, and modify MongoDB. mongod is started on the MongoDB server.ProgramMongo is the MongoDB shell, which can be considered as a client and a JS compiler. It is connected to the Test Library by default.
CodeCd c: \ MongoDB \ binmongo
- Insert operation
DB. Person. insert ({"name": "Jack", "Age": 20 })
DB. Person. insert ({"name": "Joe", "Age": 25 })
The above two lines of commands insert two lines of records into the set person. Note that if the set person does not exist, a new one will be created directly.
- Find operation
DB. Person. Find ()
DB. Person. Find ({"name": "Joe "})
The find method without any parameters lists all records in the set.
- Update operation
DB. Person. Update ({"name": "Joe" },{ "name": "Joe", "Age": 35 })
Note that the second parameter in update, that is, the target value, must contain a complete field. Otherwise, other fields will become null.
- Remove operation
DB. Person. Remove ()
Note that this operation will delete all data without any parameters and cannot be withdrawn.