Mongovue, a fairly good MongoDB manager, with MongoDB used in read-only free version C #

Source: Internet
Author: User

Mongovue, a fairly good MongoDB manager with a read-only free version.

Mongod.exe -- dbpath D: \ mongodb-win32-i386-2.0.2 \ bin \ data

 

Use MongoDB in C #

First, download MongoDB from the Internet. Go to http://www.mongodb.org/and find the download address of the latest website.

This is my download.

Create a folder on the E drive, decompress the downloaded ZIP file, and copy all the files in the bin directory to the folder you just created.

Create a data folder.

Then use cmd to start your MongoDB

You can check the red lines. --

Access localhost: 27017 and you will see the following information, indicating that your MongoDB has been started.

 

Added:

 Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. runtime. serialization;
Using System. Data;
Using System. Data. sqlclient;
Using MongoDB. bson;
Using MongoDB. driver;

Namespace Leleapplication1
{
Class Program
{
Static Void Main ( String [] ARGs)
{
// Connection information
String Conn = " MongoDB: // localhost " ;
String Database = " Demobase " ;
String Collection = " Democollection " ;

Login Server MongoDB = Login server. Create (conn ); // Connect to database
Relational Database relational database = MongoDB. getdatabase (database ); // Select Database Name
Collections collection collections collection = collections database. getcollection (Collection ); // Select a set, which is equivalent to a table

MongoDB. Connect ();

// Normal insert
VaR O = New {Uid = 123 , Name = " Xixinormal " , Password = " 111111 " };
Collections collection. insert (O );

// Object insertion
Person P = New Person {uid = 124 , Name = " Xixiobject " , Password = " 222222 " };
Collections collection. insert (P );

// Bsondocument insertion
Bsondocument B = New Bsondocument ();
B. Add ( " UID " , 125 );
B. Add ( " Name " , " Xixibson " );
B. Add ( " Password " , " 333333 " );
Collections collection. insert (B );

Console. Readline ();
}
}

Class Person {
Public Int UID;
Public String Name;
Public String Password;

}
}
Copy code

Result:

Both are written in the preceding configuration,ProgramThe corresponding database and set are automatically created.

The following operations are incomplete.CodeNow:

             /*  ---------------------------------------------
* SQL: Select * from table
*---------------------------------------------
*/
Export cursor <person> P = your collection. findallas <person> ();

/* ---------------------------------------------
* SQL: Select * from table where uid> 10 and uid <20
*---------------------------------------------
*/
Querydocument query = New Querydocument ();
Bsondocument B = New Bsondocument ();
B. Add ( " $ GT " , 10 );
B. Add ( " $ Lt " , 20 );
Query. Add ( " UID " , B );

Using cursor <person> M = collecting collection. findas <person> (query );

/* -----------------------------------------------
* SQL: Select count (*) from table where uid> 10 and uid <20
*-----------------------------------------------
*/
Long C = fetch collection. Count (query );

/* -----------------------------------------------
* SQL: Select name from table where uid> 10 and uid <20
*-----------------------------------------------
*/
Querydocument query = New Querydocument ();
Bsondocument B = New Bsondocument ();
B. Add ( " $ GT " , 10 );
B. Add ( " $ Lt " , 20 );
Query. Add ( " UID " , B );
Fieldsdocument F = New Fieldsdocument ();
F. Add ( " Name " , 1 );

Export cursor <person> M = your collection. findas <person> (query). setfields (f );
/* -----------------------------------------------
* SQL: Select * from Table order by uid DESC limit 10, 10
*-----------------------------------------------
*/
Querydocument query = New Querydocument ();
Sortbydocument S = New Sortbydocument ();
S. Add ( " UID " ,- 1 ); // -1 = DESC

Export cursor <person> M = collections collection. findallas <person> (). setsortorder (s). setskip ( 10 ). Setlimit (10 );
Copy code

First, download MongoDB from the Internet. Go to http://www.mongodb.org/and find the download address of the latest website.

This is my download.

Create a folder on the E drive, decompress the downloaded ZIP file, and copy all the files in the bin directory to the folder you just created.

Create a data folder.

Then use cmd to start your MongoDB

You can check the red lines. --

Access localhost: 27017 and you will see the following information, indicating that your MongoDB has been started.

 

Added:

 Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. text;
Using System. runtime. serialization;
Using System. Data;
Using System. Data. sqlclient;
Using MongoDB. bson;
Using MongoDB. driver;

Namespace Leleapplication1
{
Class Program
{
Static Void Main ( String [] ARGs)
{
// Connection information
String Conn = " MongoDB: // localhost " ;
String Database = " Demobase " ;
String Collection = " Democollection " ;

Login Server MongoDB = Login server. Create (conn ); // Connect to database
Relational Database relational database = MongoDB. getdatabase (database ); // Select Database Name
Collections collection collections collection = collections database. getcollection (Collection ); // Select a set, which is equivalent to a table

MongoDB. Connect ();

// Normal insert
VaR O = New {Uid = 123 , Name = " Xixinormal " , Password = " 111111 " };
Collections collection. insert (O );

// Object insertion
Person P = New Person {uid = 124 , Name = " Xixiobject " , Password = " 222222 " };
Collections collection. insert (P );

// Bsondocument insertion
Bsondocument B = New Bsondocument ();
B. Add ( " UID " , 125 );
B. Add ( " Name " , " Xixibson " );
B. Add ( " Password " , " 333333 " );
Collections collection. insert (B );

Console. Readline ();
}
}

Class Person {
Public Int UID;
Public String Name;
Public String Password;

}
}
Copy code

Result:

All are written in the preceding configuration. The program automatically creates the corresponding database and set.

The following operation is not complete:

             /*  ---------------------------------------------
* SQL: Select * from table
*---------------------------------------------
*/
Export cursor <person> P = your collection. findallas <person> ();

/* ---------------------------------------------
* SQL: Select * from table where uid> 10 and uid <20
*---------------------------------------------
*/
Querydocument query = New Querydocument ();
Bsondocument B = New Bsondocument ();
B. Add ( " $ GT " , 10 );
B. Add (" $ Lt " , 20 );
Query. Add ( " UID " , B );

Using cursor <person> M = collecting collection. findas <person> (query );

/* -----------------------------------------------
* SQL: Select count (*) from table where uid> 10 and uid <20
*-----------------------------------------------
*/
Long C = fetch collection. Count (query );

/* -----------------------------------------------
* SQL: Select name from table where uid> 10 and uid <20
*-----------------------------------------------
*/
Querydocument query = New Querydocument ();
Bsondocument B = New Bsondocument ();
B. Add ( " $ GT " , 10 );
B. Add ( " $ Lt " , 20 );
Query. Add ( " UID " , B );
Fieldsdocument F = New Fieldsdocument ();
F. Add ( " Name " , 1 );

Export cursor <person> M = your collection. findas <person> (query). setfields (f );
/* -----------------------------------------------
* SQL: Select * from Table order by uid DESC limit 10, 10
*-----------------------------------------------
*/
Querydocument query = New Querydocument ();
Sortbydocument S = New Sortbydocument ();
S. Add ( " UID " ,- 1 ); // -1 = DESC

Export cursor <person> M = collections collection. findallas <person> (). setsortorder (s). setskip ( 10 ). Setlimit ( 10 );
Copy code

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.