MongoDB Mongo csharp driver: https://github.com/mongodb/mongo-csharp-driver/downloads
For details, visit the official MongoDB website.
The following example shows a simple query:
// Create a database connection. The default local connection port is 27017.
Mongoserver Server = Login server. Create ();
// Obtain the database. If not, it is automatically created.
Relational Database = Server. getdatabase ( " Mydatabase " );
// Get collection set
Mongocollection things = Database. getcollection ( " Things " );
Try
{
// Open connection
Server. Connect ();
// Set the query condition X like (3, 4)
Queryconditionlist Condition = New Queryconditionlist ( " X " );
Condition. In ( New Bsonarray (). Add ( New Bsonint32 ( 3 ). Add ( New Bsonint32 ( 4 )));
Mongocursor < Bsondocument > Cur = Things. findas < Bsondocument > (Condition );
Foreach (Bsondocument item In Cur)
{
MessageBox. Show (item [ " J " ]. Asdouble. tostring ());
}
}
Finally
{
// Close connection
Server. Disconnect ();
}
In Mongo CSHARP driver, there are mainly driver and bson packages.In the above example, we use several classes
Mongoserver
Relational Database
Collections collection
Queryconditionlist
Mongocursors
In the future, we will first analyze these categories to implement database addition, deletion, modification, and query functions.