软件编程
位置:首页>> 软件编程>> C#编程>> dotnet core链接mongodb代码实例

dotnet core链接mongodb代码实例

作者:mlh1421  发布时间:2023-07-20 14:26:09 

标签:dotnet,core,链接,mongodb

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

来源:https://www.cnblogs.com/mlh1421/p/11913061.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com