这篇文章主要介绍了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);//添加一条数据

以上就是【dotnet core链接mongodb代码实例】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)

与本文相关的软件

发表我的评论

最新评论

  1. 暂无评论