dotnet core 链接mongodb

导入命名空间

using MongoDB.Bson;
using MongoDB.Driver;

 

测试示例:

var client = new MongoClient("mongodb://127.0.0.1:27017");
            var database = client.GetDatabase("foo");
            var collection = database.GetCollection<object>("app");
            var document = new 
            {
                name="添加到mongodb"
            };
            var a= collection.AsQueryable<object>();//查询
            Console.WriteLine(a.Count());
            collection.InsertOne(document);//添加一条数据

 

posted @ 2019-11-22 17:48  liliyou  阅读(104)  评论(0编辑  收藏  举报