Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Database \ Use MongoDB C # MongoDB official driving operation     - To install Ganglia configuration of experience under CentOS 5.5 (Linux)

- Oracle partition table data migration, process management automation (Database)

- Oracle 11g RAC automatically play GI PSU patch ( (Database)

- The file name is garbled or deleted files with special characters under Linux (Linux)

- Windows Desktop use VNC remote connect Linux (Linux)

- RHEL6.4 x86_64 build SVN service (Server)

- Polymorphism of the C ++ compiler and run-time polymorphism (Programming)

- VirtualBox virtual machine to install Linux (Linux)

- How to Create a file can not be changed under Linux (Linux)

- Processor in protected mode of protection (Linux)

- Java, on the dfile.encoding Systemproperty (Programming)

- Denyhosts prevent hackers using SSH scanning (Linux)

- Create a project using Android Studio LinearLayout (Programming)

- WordPress blog installation Redis Cache (Server)

- Udev: Device Manager for Linux Fundamentals (Linux)

- Realize screen recording and playback via Linux command (Linux)

- Sublime Text 3 practical functions and shortcut keys used to collect (Linux)

- ORA-00020: No more process state objects available (Database)

- Fedora 22 Server how to upgrade to Fedora 23 Beta Server (Linux)

- The relationship between UNIX and Linux (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;}
- iTerm - let your command line can also be colorful (Linux)
- Linux basic introductory tutorial ---- Software Installation under Linux (Linux)
- Java eight new features 8 (Programming)
- Netcat Example (Linux)
- CentOS ClamAV antivirus package updates (Linux)
- MySQL restart process can not be taken lightly (Database)
- CentOS 6.5 minimal installation and configuration VMware tools (Linux)
- JavaScript function part (Programming)
- Java collections series (Programming)
- Spring declarative transaction management (Programming)
- Using VMware vSphere Client Linux virtual machine installation CentOS6.4 system (Linux)
- Linux use chattr and lsattr commands to manage file and directory attributes (Linux)
- The practical application of Oracle synonyms + dblink (Database)
- Ubuntu 14.10 How to install office suite Calligra Suite 2.8.7 (Linux)
- Analysis examples: Intrusion Response Linux platform Case (Linux)
- Ten best plug surge Emacs Productivity (Linux)
- IntelliJ IDEA common list of shortcuts (Linux)
- Ubuntu users install the video driver Nvidia Driver 334.21 (Linux)
- CentOS5 installation Nodejs (Linux)
- Binary Tree Traversal (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.