MongoDB initial experience-C #

Source: Internet
Author: User
Tags git client

I think we have used relational databases as frequently-used tools as the tietong header. in the software development process, almost all the data storage is inseparable from relational databases, ms SQL, etc ). after several years of design optimization, performance, security, and manageability improvement, the current Relational Database Service is obviously an outstanding achievement in the software engineering process. However, relational databases are not the best choice in some data storage application scenarios.

I have been paying attention to the development of "no-SQL" data storage in the past few months. I want to attend a no-SQL Conference (nosqleast-their slogan is: Select fun, profit from real_world where relational = false). I had to wait for Matt before that. P (Translator's note: may be a member of the meeting's organization. The following are some good examples of No-SQL.Article:

    • Dare Obasanjo: building scalable databases: denormalization, The nosql movement and Digg
    • Eric florenzano: my thoughts on nosql

 

I want to personally experience the document-type database, so I chose MongoDB, which can be seen on its FAQ page:

MongoDB is a document-type database management system. You can regard it as a storage space for persistent objects. It is neither relational nor "data table oriented" like "Amazon simpledb" or "Google bigtable. If you were in yourProgramAfter using the ORM tool, you will find that the APIS provided by MongoDB are similar, easy to use, but more powerful.

I chose MongoDB because it looks easy to configure..., as shown below:

1. Download and decompress the file from MongoDB.

2. Create a file: C: \ data \ dB (default data storage directory-changed)

3. Run cmdd.exe

For communication with MongoDB in the program, I use MongoDB-CSHARP. You can download the source code package directly, or copy the source code from the GitHub website using a git client such as git on Windows (Note: git is a popular source code management method. It may sound a little troublesome to use git, but it will be very convenient to get started, and it is very fast to get the latest source code through git. Download the source code and compile it with vs to get an Assembly named MongoDB. Driver. With this assembly, you can use MongoDB in your c # project:

Link to MongoDB in the program as follows:

 
VaR Mongo =NewMongo (); Mongo. Connect (); var DB = Mongo. getdb ("Moviereviews");

I use MongoDB on my local computer. It listens to the default port set during installation and does not require special security settings. ThereforeCodeIn the above code, I obtain a database named "moviereviews". If it does not exist, MongoDB will automatically create one. I don't need to create a table or set a primary key or something. Using document-based databases and relational databases is like using dynamic and static languages. (Note: javascript can be regarded as a dynamic language, and C # can be regarded as a dynamic language ).

The next step is to get or create a list (Collection) and add a document for this list:

VaR movies = dB. getcollection ("Movies"); var movie = new document (); movie ["title"] = "Star Wars"; movie ["releasedate"] = datetime. now; movies. insert (movie );

In MongoDB, the list is similar to a table in the relational database World. The difference is that the list consists of binary JSON files instead of rows and columns, therefore, such documents can contain anything (you can serialize them to binary JSON)-they are non-table framework type. MongoDB knows how to query and index data.

 
VaR spec = new document (); spec ["title"] = "Star Wars"; var starwars = movies. findone (SPEC );

The appropriate abstraction of data storage, coupled with a little of the LINQ feature, document-based databases may become a highlight of. NET applications. If you have built-in support for. NET Dynamic Language Runtime, it would be better.

 

Address: http://odetocode.com/Blogs/scott/archive/2009/10/13/experimenting-with-mongodb-from-c.aspx

Technorati label: MongoDB, NO-SQL
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.