MongoDB Development Learning

Source: Internet
Author: User
Tags mongodb version
If you have never been familiar with MongoDB or have a little understanding of MongoDB, if you are a C # developer, take a few minutes to read this article. This article will take you step by step to get started easily. Read directory 1. Introduction MongoDB is a Database Based on Distributed File storage. Written in C ++. Designed to provide scalable and high-performance data storage solutions for WEB Applications

If you have never been familiar with MongoDB or have a little understanding of MongoDB, if you are a C # developer, take a few minutes to read this article. This article will take you step by step to get started easily. Read directory 1. Introduction MongoDB is a Database Based on Distributed File storage. Written in C ++. Designed to provide scalable and high-performance data storage solutions for WEB Applications

If you have never been familiar with MongoDB or have a little understanding of MongoDB, if you are a C # developer, take a few minutes to read this article. This article will take you step by step to get started easily.

Reading directory

I. Introduction

MongoDB is a distributed file storage-based database. Written in C ++. It is designed to provide scalable, high-performance data storage solutions for WEB applications.

MongoDB is a high-performance, open-source, and non-pattern document-based database. It is a popular NoSql database.

MongoDB is a product between relational databases and non-relational databases. It features the most abundant features in non-relational databases, and is the most like a relational database in Hong Kong virtual host. The supported data structure is very loose and is similar to the json bjson format. Therefore, it can store complicated data types. The biggest feature of Mongo is that it supports a very powerful query language. Its syntax is somewhat similar to an Object-Oriented Query Language. It can almost implement most of the functions similar to single-table queries in relational databases, it also supports data indexing.

Traditional relational databases are generally composed of three levels: database, table, and record. MongoDB is composed of databases and collections) and document objects. MongoDB has no concept of columns, rows, and links for tables in relational databases, which reflects the free mode.

Ii. Features

It features high performance, ease of deployment, and ease of use, making it easy to store data. Features:

1) oriented to centralized storage, it is easy to store object-type data.

2) Free mode.

3) supports dynamic query.

4) supports full indexing, including internal objects.

5) query is supported.

6) supports replication and fault recovery.

7) use efficient binary data storage, including large objects (such as videos ).

8) automatically process fragments to support scalability at the cloud computing level.

9) supports RUBY, PYTHON, JAVA, C ++, PHP, C #, and other languages.

10) the file storage format is BSON (a json extension ).

11) accessible through the network.

3. Download, install, and enable the server

3.1) The current MongoDB version is 2.0.4 ,:. Provides versions of various platforms. I chose Windows.

3.2) Create the directory E: \ mongodb and decompress the downloaded package to this directory. The binfile contains a pile of. EXE files.

There are two most important files: mongod.exeand cmd.exe.

Mongod.exe is used to connect to the mongo database server, that is, the server side.

Cmd.exe is used to start the MongoDB shell, that is, the client.

Other files:

Mongodump logical backup tool.

Mongorestore logical recovery tool.

Export export data export tool.

Mongoimport data import tool.

3.3) Enable the server

Step 1: create a directory to store MongoDB database files, that is, dbpath. You can create it wherever you like. Here I create E: \ MongoDBFiles. This is for the next step.

Step 2: Open the CMD window and enter the following command:

> E:

& Gt; cd e: \ mongodb \ mongodb-win32-i386-2.0.4 \ bin

> Mongod.exe-dbpath "E: \ mongodbfiles"

The value of the-dbpath parameter in the last command line is the folder created in step 1. This folder must be created before the service is enabled. Otherwise, an error will be reported. mongodb will not be created on the Hong Kong virtual host.

If the operation is successful, the following interface is displayed:

This interface shows some information: for example, the process ID is 2988 and the port number is 27017.

Open the browser and enter: 27017/

We see the following prompt:

"You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number"

By now, the MongoDB Database Service has been successfully started.

4. Use cmd.exe to add, delete, modify, and query Databases

Mongodb is our local client management tool named "cmd.exe ".

4.1) Create a database:

Double-click cmd.exe to display the following interface:

This interface means that the currently connected database is test, which will be created by default by the system. Why is it "to be created? Because the database does not exist at this time, or it is still in the memory and is not created on a physical disk. Believe it or not, you can see that there is nothing except mongod. lock In the MongoDBFiles folder. The database is created only when you execute the data insertion command.

Okay. We don't care about this test for the time being. Create a database named cnblogs.

In the shell command window, type the following command:

> Use cnblogs // use command to switch to the current database. If the database does not exist, a new one is created first.

4.2) create a collection and insert data

In traditional relational databases, tables are created after the database is created, but there is no "table" concept in mongoDB. A corresponding concept is set, that is, collection.

In the shell command window, type the following command:

> Db. users. insert ({'name': 'xumingxiang ', 'sex': 'man '})
// This command inserts a piece of data into the users set. If the set users does not exist, a new one will be created first, and then data will be inserted. The parameter is passed in JSON format.

We need to test data deletion later, so we need to insert another data entry:

> Db. users. insert ({'name': xiangshu ', 'sex': 'man '})

4.3) in the above 4.1) and 4.2) Have we created a database, created a set, and inserted two pieces of data? Have these operations been successfully performed? Let's query:

In the shell command window, type the following command:

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.