MongoDb is one of the good NoSQL databases. NoSQL means Not Only SQL, which is easier to expand than relational databases such as MySQL and SQL Server, and more suitable for storing massive data, data can be elastically scalable across LAN and WAN, making it more suitable for cloud environments. MongoDB needs to be used in a recently started project. Here, we will try to install and test it on the local machine.
MongoDB can be downloaded from the official website and decompressed to a directory, such as C: \ MongoDB. To run MongoDB, create two directories:
C: \ MongoDB \ data is used to store data
C: \ MongoDB \ log used to store logs
Then go to the command line:
C: \ MongoDB \ bin> mongod.exe -- dbpath c: \ mongodb \ data
The server can be started.
Then open a cmd window, run mongo, and connect to the server:
C: \> cd MongoDB
C: \ MongoDB> cd bin
C: \ MongoDB \ bin> mongo
MongoDB shell version: 2.4.3
Connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help ".
For more comprehensive documentation, see
Http://docs.mongodb.org/
Questions? Try the support group
Http://groups.google.com/group/mongodb-user
NoSQL such as MongoDB is different from common relational databases. It does not have a fixed structure but is saved in the form of documents. The following is a test example:
> Db. test. save ({a: 1}); // save a record a = 1 in the test table (for the moment ).
> Db. test. find (); // query all records
{"_ Id": ObjectId ("517b4b3823c489619d958d66"), "a": 1}
>
Add several more records. Note that these new records contain several more fields:
> Db. test. save ({name: 'lisi', score: 87, grade: 'good '});
> Db. test. save ({name: 'hangw', score: 61, grade: 'pass '});
> Db. test. find ();
{"_ Id": ObjectId ("517b4b3823c489619d958d66"), "a": 1}
{"_ Id": ObjectId ("517b4eba23c489619d958d67"), "name": "zhang san", "score ":
93}
{"_ Id": ObjectId ("517b4f3523c489619d958d68"), "name": "lisi", "score": 87 ,"
Grade ":" good "}
{"_ Id": ObjectId ("517b4f5023c489619d958d69"), "name": "wangwu", "score": 61,
"Grade": "pass "}
>
We can see that MongoDB is very flexible to use. The specific usage will be further studied.