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;
}
}
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 );