zoukankan      html  css  js  c++  java
  • mongoDB之C#and.net Driver

      之前一直都是用NodeJS来连接操作mongoDB的,但是最近需要用C#操作mongoDB的需要,所以研究了下C#驱动。mongoDB官方在GitHub上提供了C#驱动源码https://github.com/mongodb/mongo-csharp-driver。源码下载好之后编译得到MongoDB.Bson.dll和MongoDB.Driver.dll两个文件,我已经编译好了http://yunpan.cn/QCFn3v86KaEST  访问密码 f0ef。

      将两个文件添加到项目引用然后在程序中添加相应的using语句。然后对其进行简单的操作:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    using MongoDB.Bson;
    using MongoDB.Driver;
    
    namespace MongoDBDriverLearn
    {
        class Program
        {
            static void Main(string[] args)
            {
                var client = new MongoClient("mongodb://sa:sa@localhost:27017");
                var server = client.GetServer();
                var database = server.GetDatabase("demoDatabase");
                var collection = database.GetCollection("demoCollection");
    
                collection.Insert(new BsonDocument("Name", "Jack"));
    
                foreach (var document in collection.FindAll())
                {
                    Console.WriteLine(document["Name"]);
                }
    
                Console.Read();
            }
        }
    }

     

  • 相关阅读:
    19.Mybatis之动态SQL
    18.Mybatis的配置文件标签属性自动提示
    17.Mybatis的基本使用及入门案例
    16.jQuery属性操作
    15.jQuery淡入淡出效果
    14.jQuery常用方法
    13.jQuery选择器
    12.JavaScript基础知识
    11.浅析Java中的final关键字
    10.基于Tomcat的SmartUplaod文件上传
  • 原文地址:https://www.cnblogs.com/henuadtc/p/3858059.html
Copyright © 2011-2022 走看看