首页 > 数据库技术 > 详细

C# 访问 MongoDB 数据库

时间:2015-03-27 20:06:25      阅读:228      评论:0      收藏:0      [点我收藏+]

1. 添加dll

MongoDB.Bson.dll

MongoDB.Driver.dll

MongoDB.Driver.TestHelpers.dll


2. 引用命名空间

using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.GridFS;


3.使用如下代码:

            MongoServerAddress address = new MongoServerAddress("localhost", 27017);
            MongoServerSettings setting = new MongoServerSettings();
            setting.Server = address;
            MongoServer server = new MongoServer(setting);
            MongoDatabase mydb = server.GetDatabase("dxl");
            string localFileName = @"C:\MongoDB\data\C#高级编程(第7版).pdf";
            string mongoDBFileName = "C#高级编程(第7版).pdf";
            MongoGridFSSettings fsSetting = new MongoGridFSSettings(){Root = "dxl"};
            MongoGridFS gridfs = new MongoGridFS(mydb, fsSetting);
            gridfs.Upload(localFileName, mongoDBFileName);


效果:

技术分享

C# 访问 MongoDB 数据库

原文:http://blog.csdn.net/dingxl555/article/details/44679557

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!