There are three elements in mongodb: database, collection, document, and “collection”
It corresponds to the table in the relational database and the document corresponds to the row.
On the mongodb official website, we found that there are 32bit and 64bit, which depends on your system, but here are two points:
① According to the industry rules, the even number is “stable version” (e.g. 1.6. X, 1.8. X), and the odd number is “development version” (e.g. 1.7. X, 1.9. X). We all know the difference between the two versions.
② : 32 bit mongodb can only store 2G data at most, and 64 bit has no limit.
I’ll download “version 2.0.2, 32bit”, OK. After downloading, I’ll put it on “e disk” and change the folder name to “mongodb”.
Two: start up
① : before starting, we need to specify a folder for mongodb, named “DB” here, to store mongodb’s data.
② : Microsoft logo + R, enter CMD, first find the path of “mongodb”, then run the mongod open command, and use — dbpath to specify the data storage location as “DB” folder.
③ : finally, it depends on whether it is opened successfully. From the information in the figure, we know that mongodb uses 27017 port, so we type “http: / / localhost: 27017 /” in the browser,
After opening, mongodb tells us that add 1000 can view mongodb’s management information in HTTP mode on 27017.
3： Basic operation
Since it’s the beginning of the article, let’s roughly say the basic “add, delete, search and modify”. We open another CMD, and enter the Mongo command to open the shell. In fact, the shell is the client of mongodb,
At the same time, it is also a JS compiler. The default connection is the “test” database.
<1> Insert operation
OK, the next step for the database is the collection. Here, the collection is named “person”. Note that the document is a JSON extension (bson).
<2> Find operation
After inserting the data, we must find it out, otherwise we will insert it in vain. Here we should pay attention to two points:
① “_id”: this field is the guid that the database adds to us by default. The purpose is to ensure the uniqueness of data.
② Write documents strictly in bson’s form, but it doesn’t matter. Error tips are powerful.
<3> Update operation
The first parameter of the update method is “search condition”, and the second parameter is “updated value”. After learning C, I believe it is well understood.
<4> Remove operation
In remove, all data will be deleted without parameters. Ha ha, it’s a very dangerous operation. In mongodb, it’s an irreversible operation. Think twice before you go.