1024programmer Mongodb Introduction to the use of MongoDB database C# driver

Introduction to the use of MongoDB database C# driver

1: Brief Introduction

Special Topic: NoSOL: Relational Database Terminator?

MongoDB is a distributed document database that supports a master-slave structure similar to a relational database. Documents are stored in the form of binary Json, lock-free, transaction-free, and indexed.

2: Installation steps

Step 1: Download the assembly http://www.mongodb.org/downloads

Part 2: Unzip and extract the relevant bin directory to C:\Mongo (this is optional), and create a db folder under this directory.

Part 3: Open the CMD window, enter the C:\Mongo\bin directory, and run mongod.exe
–dbpath=”c:\Mongo\db”

Step 4: Open the CMD window again (keep the previous window open) and run mongo.exe. In this window you can execute simple commands, a few are briefly listed below

> j = { name : “mongo” };
the

{“name”: “mongo”}

> t = { x : 3 };
the

{ “x” : 3 }

> db.things.save(j);

> db.things.save(t);

> db.things.find();

{ “_id” : ObjectId(“4c2209f9f3924d31102bd84a”), “name” : “mongo” }
the

{ “_id” : ObjectId(“4c2209fef3924d31102bd84b”), “x” : 3 }
the

>

> for (var i = 1; i <= 20; i++) db.things.save({x : 4, j : i});
the

> db.things.find();

> var cursor = db.things.find();
the

> while (cursor.hasNext()) printjson(cursor.next());
the

> db.things.find().forEach(printjson);

> var cursor = db.things.find();
the

> printjson(cursor[4]);

> var arr = db.things.find().toArray();
the

> arr[5];

> db.things.find({name:”mongo”}).forEach(printjson);
the

> db.things.find({x:4}, {j:true}).forEach(printjson);
the

> printjson(db. things. findOne({name: “mongo”}));
the

> db.things.find().limit(3);

3: C# version driver

Several C# version drivers are listed below, and a brief introduction is given.

The first one: mongodb-csharp
Project address: http://github.com/samus/mongodb-csharp

Brief introduction: This driver is a relatively comprehensive driver, and the update is very fast. Some people have already applied it to the project, and the performance is very good. At present, their team is working on the expansion of connection management functions such as: automatic reconnection, connection pool and so on.

The second item: mongodb-net project address: http://code.google.com/p/mongodb-net/

Brief introduction: the development is still in progress, some functions have not been implemented yet

The third one: MongoDB. Emitter
Project address: http://bitbucket.org/gwbasic/mongodb.emitter/

Brief introduction: Provides strong type support

The fourth paragraph: CSMongo
Project address: http://somewebguy.wordpress.com/2010/02/21/building-a-mongo-driver-part-1/

Brief introduction: Some functions have been realized, and there is no downloadable code. But you can read his blog to understand this driving thinking.

Fifth paragraph: simple-mongodb
Project address: http://code.google.com/p/simple-mongodb/

Brief introduction: No source code is provided, and JSon is the core.

The last one is an enhancement to some parts of the first paragraph, address http://deserialized.com/convert-csharp-classes-to-and-from-mongodb-documents-automatically-using-net-reflection

Item 6: NoRM project address: http://github.com/atheken/NoRM

Introduction: The first type is enhanced to support strong typing.

Extended reading

MongoDB LOGO

MongoDB Logo

Mongo is a high-performance, open-source, schema-free document database that can be used in many scenarios to replace traditional relational databases or key/value stores. Mongo is developed in C++ and provides the following functions:

◆Set-oriented storage: suitable for storing objects and data in the form of JSON.

◆Dynamic query: Mongo supports rich query expressions. The query command uses JSON format tags, which can easily query the embedded objects and arrays in the document.

◆Complete index support: including document embedded objects and arrays. Mongo’s query optimizer analyzes query expressions and generates an efficient query plan.

◆ query monitoring: Mongo includes a monitoring tool for analyzing the performance of database operations.

◆Copy andAutomatic failover: Mongo database supports data replication between servers, master-slave mode and mutual replication between servers. The main goal of replication is to provide redundancy and automatic failover.

◆Efficient traditional storage method: supports binary data and large objects (such as photos or pictures).

◆Automatic sharding to support cloud-level scalability (in early alpha stage): The automatic sharding feature supports horizontal database clusters and can dynamically add additional machines.

The main goal of MongoDB is to build a bridge between the key/value storage method (providing high performance and high scalability) and the traditional RDBMS system (rich functions), combining the advantages of both. According to the description on the official website, Mongo is suitable for the following scenarios:

◆Web site data: Mongo is very suitable for real-time insertion, update and query, and has the replication and high scalability required for real-time data storage of the website.

◆Cache: Due to its high performance, Mongo is also suitable as a cache layer for information infrastructure. After the system is restarted, the persistent cache layer built by Mongo can prevent the underlying data source from being overloaded.

◆Large size, low-value data: It may be expensive to store some data using traditional relational databases. Before that, programmers often choose traditional files for storage.

◆High-scalability scenarios: Mongo is very suitable for databases consisting of dozens or hundreds of servers. Mongo’s roadmap already includes built-in support for the MapReduce engine.

◆Used for storage of objects and JSON data: Mongo’s BSON data format is very suitable for storage and query in document format.

Naturally, the use of MongoDB will also have some limitations, for example it is not suitable for:

◆Highly transactional systems: such as banking or accounting systems. Traditional relational databases are still more suitable for applications that require a large number of atomic complex transactions.

◆Traditional business intelligence applications: BI databases for specific issues will generate highly optimized query methods. For such applications, a data warehouse may be a more appropriate choice.

◆Problems requiring SQL

MongoDB supports OS
Operating systems such as X, Linux, and Windows provide drivers for Python, PHP, Ruby, Java, and C++. The community also provides drivers for platforms such as Erlang and .NET.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/introduction-to-the-use-of-mongodb-database-c-driver/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索