Helloword for MongoDB

Source: Internet
Author: User
Tags mongodb server mongodb tutorial

I was not very busy recently. I just wanted to play with nosql. After reading the MongoDB tutorial, I was attracted by its simplicity. So I couldn't help but want to write out the results of the morning search and share them with me, it's worth mentioning.

1) first install the MongoDB server. download it from here.

2) My system is win7 flagship, so the download is mongodb-win32-i386-1.9.0 this or non-stable version.

You can use commands to create a data file storage directory.

Do not close this window. If you close the window, you will understand it.

3) download the C # client here.

4) create a console project and add DLL reference (if the source code is below, you can add a new console project in the original solution and then add the project reference .)

Connect to the server

You can write the following code to connect to MongoDB:

In this way, the default host is localhost. If you want to use other hosts and ports, you can choose another reset method.

Obtain database instances

Here, we still need to create a database. You can use the getdatabase method to create and return the "mymongodb" database instance. The source code of getdatabase is as follows:

Refer to "table"

MongoDB does not have the concept of "Table". MongoDB regards all records as "document ". Replace familiar tables with document sets.

In this way, a set of documents named "Hello" is created.

Document recognition: Everything is a document

In the MongoDB world, you can use document to insert data, update data, and query data. The document is at the core here. Insert a helloword record first.

You can output records by traversing the document set.

I think MonoDB is worth it.

Reference: http://jasona.wordpress.com/2010/02/04/getting-started-with-mongodb-and-c/

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.