Introduction to using CSharp Driver to operate Mongodb

Source: Internet
Author: User
  • Introduction

I have some experience with Mongodb:

I do not mention its step-by-step and efficiency features. At least the following features make me feel that it is unnecessary to use relational databases such as SQLServer in common application scenarios.

1. Eliminating ORM: for example, nhib.pdf is an excellent ORM with good performance. But you have to learn the expression syntax of nhib.pdf. It is acceptable to have a sound documentation like NH.

I have some more terrible experiences. I have written a lot of code that is manually mapped to objects after I use stored procedure queries.
2. Green: Mongodb. If you do not want to register as a service, you only need to start the exe. The database and database Data files can be completely copied and migrated.
3. GridFS. directly store the file in the database
4. Support for various programming languages.
Officially supported:
C
C # and. NET
C ++
Erlang
Haskell
Java
Javascript
Perl


The open-source community supports more:
I don't want to list it. I haven't heard of many languages. Even a small number of Mars languages support it.

Mongodb Official Website: http://www.mongodb.org/downloads
C # Mongodb has many Driver versions. this article only introduces Csharp Driver on the official mongodb website. this Driver is currently the most popular in C # and supports the most perfect one. It supports MapReduce, but the latest version does not support query by using the Linq method. it is not so intuitive to construct a Query expression for Query. This is a bit OUT. see specific: http://www.mongodb.org/display/DOCS/CSharp+Language+Center

  • Two recommended management tools

1. Movie vue: the interface is intuitive and easy to use. However, it is only available for commercial use.
2. RockMongo: PHP + NGinx is free of charge. Currently, I have used a few of them, which is the most reliable.

  • CRUD operation example: (the sample code is better than my own)
Connect to the database // your server manages access to your database
Login Server login server = Login server. Create ("mongodb: // localhost: 27017 ");

// Restore database used to access your collection instances
_ Your database = Login server. GetDatabase ("CodeCamp ");
String COLLECTION = "Artists ";
Var artist = new Artist () {Name = "The Decembrists "};

// Insert an object directly,
_ Your database. GetCollection <Artist> (COLLECTION)
. Insert (artist );

// Update
Artist. Name = "The Decemberists ";
_ Your database. GetCollection <Artist> (COLLECTION)
. Save (artist );
// Update a batch
_ Your database. GetCollection <Artist> (COLLECTION). Update (
Query. EQ ("Name", "The Decemberists "),
Update. PushAll ("Albums", "Castaways and Cutouts", "Picaresque", "Hazards of Love", "The Crane Wife ")
);

More complex gameplay: see

Why /? Cid = 4c2acd76fe2dcc19 & SC = documents & id = 4C2ACD76FE2DCC19% 21237 & retry #! /View. aspx/. Public/NYC-Code-Camp-2011-DotNet-MongoDB.pptx? Cid = 4c2acd76fe2dcc19 & SC = documents
  • Others:
There are more examples in the attached PPT, which refer to some guidelines for using document-based database object design.
  • Your object model is your data model.
  • Don't be afraid of object data redundancy
  • But do not include all the data in one document.
  • Do not be afraid to save aggregate statistics in the document
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: 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.