Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Database \ Use MongoDB C # MongoDB official driving operation     - 11 you Linux Terminal Command (Linux)

- Windows Desktop use VNC remote connect Linux (Linux)

- Btrfs file system repair techniques (Linux)

- MySQL and MariaDB traditional master-slave cluster configuration (Database)

- Use Vagrant up a local development environment tutorials (Server)

- Win8 mount disk partitions under Ubuntu (Linux)

- Linux how to handle file names that contain spaces and special characters (Linux)

- Install Ubuntu open source drawing program MyPaint 1.2.0 (Linux)

- To record command input under Linux (Linux)

- PHP security Programming Advice (Programming)

- Linux installed and tested the deployment of Kafka distributed cluster (Server)

- CentOS7 install JAVA notes (Linux)

- Linux file content inspection - cat, tac, no, more, less, head, tail, od (Linux)

- C # asynchronous delegates (Programming)

- Linux system security norms (Linux)

- WinSCP to transfer text files will automatically convert the format (Linux)

- Oracle Duplicate build DataGuard (Database)

- Running the open-source Swift under Linux platform (Linux)

- Analysis of MySQL High Availability (Database)

- PHP 5.3 New Features Detail (Linux)

  Use MongoDB C # MongoDB official driving operation
  Add Date : 2018-11-21      
  Want to use MongoDB in C #, you must first have a MongoDB supports C # version of the driver. C # version of the driver there are many, such as provided by the official, samus. Realization of ideas most similar. Here we will start with the official mongo-csharp-driver, the current version is

download link:


Get two dll after compiling

 MongoDB.Driver.dll: As the name suggests, the driver

 MongoDB.Bson.dll: serialization, Json related

 Then reference these two dll in our program.

 The following section briefly demonstrates how to use C # for MongoDB CRUD operations.


using System;
using MongoDB.Driver;
using MongoDB.Bson;

namespace ConsoleApplication1
    class Program
        static void Main (string [] args)
            // Database connection string
            string conn = "mongodb: // 27017";
            // Database name
            string database = "RsdfDb";
            string collection = "Act_User";

            MongoServer mongodb = MongoServer.Create (conn); // connect to the database
            MongoDatabase mongoDataBase = mongodb.GetDatabase (database); // Select the database name
            MongoCollection mongoCollection = mongoDataBase.GetCollection (collection); // select the collection, the equivalent of table
            mongodb.Connect ();

            // Insert common
            var o = new {UserID = 0, UserName = "admin", Password = "1"};
            mongoCollection.Insert (o);

            // Insert objects
            User user = new User {UserID = 1, UserName = "chenqp", Password = "1"};
            mongoCollection.Insert (user);

            // BsonDocument insert
            BsonDocument bd = new BsonDocument ();
            bd.Add ( "UserID", 2);
            bd.Add ( "UserName", "yangh");
            bd.Add ( "Password", "1");
            mongoCollection.Insert (bd);

            Console.ReadLine ();



using MongoDB.Bson;

namespace ConsoleApplication1
    class User
        // _ Id attribute must be, otherwise the update data being given: "Element '_id' does not match any field or property of class".
        public ObjectId _id; //BsonType.ObjectId this corresponds MongoDB.Bson.ObjectId
        public int UserID {get; set;}
        public string UserName {get; set;}
        public string Password {get; set;}
- RHEL7 Apache MPM configuration (Server)
- Alien Magic: RPM and DEB Mutual Convert (Linux)
- Python in os.path Magical (Programming)
- Shell command line operation (Linux)
- What is a logical partition management LVM, how to use in Ubuntu (Linux)
- Linux environment variable settings and save places (Linux)
- Enterprise Encrypting File System eCryptfs Comments (Linux)
- Apple Mac computer to install Windows 10 Concise Guide (Linux)
- RHEL7.0 configuration CD-ROM to the local YUM (Linux)
- Android 4.2 compilation notes (Programming)
- Oracle to start to solve the error ORA-27102 (Database)
- Linux common commands MEMO (Linux)
- Pydev installed and configured on the Eclipse (Linux)
- Spark source code compiler package (Linux)
- ActiveMQ5.10.2 version configuration JMX (Linux)
- MySQL Statistics (Database)
- Windows using SSH management Ubuntu (Linux)
- GAMIT learning materials finishing (Linux)
- JITwatch installation under Linux (Linux)
- GitLab upgrade to 8.2.0 (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.