How to be in. NET, using MongoDB

Source: Internet
Author: User
Tags mongodb windows

Recently in the study of MongoDB, the article using MongoDB in. NET is either an early driver version or the data is very small, so write an essay to record

This paper mainly records

1. What is MongoDB

2.MongoDB installation under Windows

Using MongoDB in

4. Case code

What is MongoDB

MongoDB is a document-based store (rather than a table), a product between a relational database and a non-relational database, the most versatile of the non-relational databases, most like relational databases. The data structure he supports is very loose and is a JSON-like Bson format, so you can store more complex data types. MONGO's biggest feature is that the query language he supports is very powerful, and its syntax is a bit like an object-oriented query language that almost implements most of the functionality of a relational database single-table query, and also supports indexing of data.

MONGO mainly solves the problem of access efficiency of massive data. Because MONGO is primarily supporting massive data storage, MONGO also comes with an excellent distributed file system Gridfs that can support massive data storage. Because MONGO can support complex data structures and has powerful data query capabilities, it is very popular.

We are familiar with JSON, but what is Bson?

Bson is a data storage format for MongoDB. Bson based on JSON format, the main reason to choose JSON for transformation is the universality of JSON and the schemaless characteristics of JSON.

1. Faster traversal speed

In JSON format, too large a JSON structure can cause data traversal to be very slow. In JSON, to skip a document for data reading, this document needs to be scanned, and a cumbersome data structure match, such as the matching of parentheses, and bson a big improvement to JSON is that it will have the length of each element of the JSON element in the head, This allows you to read directly to the specified point by reading the element length.

2. Easy to operate

For JSON, data storage is untyped, for example, if you want to modify a basic value, from 9 to 10, since a character becomes two, everything behind it may need to be moved backwards. Using Bson, you can specify this column as a number, then whether the number from 9 to 10 or 100, we are only stored in the number of the one on the change, does not cause the total length of the data to become larger. Of course, in MongoDB, if the number is increased from shaping to a long integer, it will cause the total length of the data to grow larger.

3. Added additional data types

JSON is a convenient format for data interchange, but its type is relatively limited. The Bson adds a "byte array" data type based on it. This makes binary storage no longer required to be Base64 converted before being stored as JSON. Greatly reduces the computational overhead and data size. Of course, in some cases, Bson has no spatial advantage over JSON because of the type concept

MongoDB Windows under Installation

 MongoDB installation is very simple, set up the installation path, always next until the end of the installation, the largest pit is the installation of MongoDB service, the following specific after the MongoDB installation of some configuration operations

1. Create the database path (data directory), log path (logs directory), log file (Mongo.log file), Configuration path (conf directory) in the root directory my installation path is: D:\Program Files\mongodb

2. Create the configuration file mongo.conf in the Conf directory with the following file contents:

Logpath=D:\Program Files\mongodb\logs\mongodb.log #日志输出文件路径logappend =true #错误日志采用追加模式, After configuring this option, the MongoDB log is appended to the existing log file instead of journal=true #启用日志文件, which is enabled by default quiet=true #这个选项可以过滤掉一些无用的日志信息 , if you need to debug use set to Falseport=27017 #端口号 default to 27017auth=true #启用验证 require username password       

Configuration complete the above 2 steps to start MongoDB

Run the cmd Input command (note the path to Mongod) Mongod--config "D:\Program files\mongodb\data \conf\mongo.conf"

3. Create and start the MongoDB service

If every time you follow step three, it would be quite a hassle to create and start the MongoDB service by following the command below, you can manage the startup and shutdown of MongoDB through the Windows service

Mongod--config "D:\Program files\mongodb\data \conf\mongo.conf"--install--servicename "MongoDB"

net start MongoDB

Test success can be entered in the browser if the presence indicates that the service installation was successful

If you need to uninstall MongoDB service run Mongod.exe--remove--servicename "MongoDB" in cmd

All right, here's what's going on today, and here's the next article that shows you how to use MongoDB in. NET and complete C # MongoDB Helper

How to be in. NET, using MongoDB

Related Article

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: 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.