Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Database \ Use MongoDB C # MongoDB official driving operation     - Articles do not resolve after opening under Ubuntu WordPress setting a fixed link (Server)

- How to add and delete bookmarks in Ubuntu (Linux)

- About Java 7 module system (Programming)

- Two network security scanning tools under ubuntu (Linux)

- Nginx concerning the location and rewrite applications proxy_pass (Server)

- Ubuntu buffalo wzr-hp-300nh brush DD-WRT router system (Linux)

- Linux Basics Tutorial: Combining awk delete data before the specified date hdfs (Linux)

- Oracle 11g + RAC + RHEL6.5 + udev + ASM + PSU installation summary (Database)

- Linux System Tutorial: How to Check MariaDB server versions (Database)

- Create Your Own Docker base image in two ways (Linux)

- CentOS installation Docker series (Linux)

- Steps to build MPICH2 development environment on CentOS 6.4 (Linux)

- The headers for the current running kernel were not found when VirtualBox installation enhancements (Linux)

- MySQL multi-master-slave synchronization (Database)

- Linux system performance tuning of Analysis (Linux)

- PuTTY Xming achieve the X11 forwarding ssh (Server)

- To install HDRMerge 0.4.3 under ubuntu (Linux)

- MySQL restart process can not be taken lightly (Database)

- Distributed File System using MogileFS (Linux)

- How to Install Redis server on CentOS 7 (Server)

  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;}
- Oracle through the alarm log view and inspect the main library, physical and snapshot standby database (Database)
- php How to prevent being injected (Linux)
- HAProxy performance under high concurrency (Server)
- Performance comparison Fibonacci recursive and non-recursive (Programming)
- CentOS 6.4 installation and configuration LNMP build PHP server runtime environment (Server)
- Ubuntu install video conversion tool Selene (Linux)
- C ++ Supplements - Smart Pointers (Programming)
- Python configuration tortuous road of third-party libraries Numpy and matplotlib (Programming)
- Linux crontab use (Linux)
- Use 3G wireless network card under Linux (Linux)
- Linux character device - a simple character device model (Linux)
- Linux 101 hack book reading notes (Linux)
- Linux disk partition batch format mount script (Linux)
- Linux Getting Started tutorial: Experience Xen Virtual Machine chapter (Linux)
- Hadoop 2.7.1 installation configuration based on availability QJM (Server)
- Spring next ActiveMQ combat (Programming)
- Fedora 22 users to install the VLC media player (Linux)
- Learning C ++ Standard Template Library and data structures (Programming)
- Source code compiled by the installation program under Linux (Linux)
- MySQL function: group_concat () function (Database)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.