主要内容

1 MongoClient

  1.1构造函数

  1.2 方法

2 IMongoDatabase

3 IMongoCollection

4 IMongoCollectionExtensions

5 DeleteResult

6 UpdateResult

7 IFindFluent<TDocument, TDocument> 继承了

8 IFindFluentExtensions

9 IAsyncCursorSourceExtensions

10 Builders<DocumentInfo> 构造器

11 FilterDefinitionBuilder<TDocument>

12 FilterDefinition<TDocument>:基本过滤器

13 ProjectionDefinitionBuilder<TDocument>

14 SortDefinitionBuilder<TDocument>

15 UpdateDefinitionBuilder<TDocument>

16 BsonDocument:表示一个BSON文档

17 IBsonSerializerExtensions:扩展自IBsonSerializer

18 BsonDeserializationContext

19 AggregateOptions

1 MongoClient

1.1构造函数

1)public MongoClient(MongoClientSettings settings);

  MongoClientSettings:和MongoUrl功能基本一致,但MongoClientSettings的属性多半是可修改类型。

2)public MongoClient(MongoUrl url);

  MongoUrl :通过构造函数public MongoUrl(string url)设置连接utl。请注意,MongoUrl 的属性均为只读类型。

3)public MongoClient(string connectionString);

  connectionString为连接字符串,标准连接字符串样式:

  mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

参数说明:

  mongodb://

    必选。指明此链接字符串具有标准格式

  username:password@

    可选。如果指定,客户端将尝试使用这些凭证登陆到具体的数据库

  host1

    必选。指定了服务器连接地址。它确定了一个主机名,IP地址,或UNIX域套接字。

  :port1

    可选。默认值为27017,如果未指定则为默认值。

  hostX

    可选。你可以指定尽可能多的主机,您将指定多个主机,例如,连接到副本集。

  /database

    可选。用于验证的数据库名称,如果连接字符串包含username:password@格式的身份验证凭据。如果没有指定/database并且包含了身份验证凭据,驱动将会验证admin 数据库

  ?options

    可选。格式为:name=value,使用&或;分隔每一对值。

  例如:mongodb://192.168.22.246,192.168.22.245:2500/?replicaSet=test&connectTimeoutMS=300000

  1)Replica Set Option

    replicaSet:指定副本集的名称。

  2)Connection Options

    ssl:默认值是false,不启动TLS / SSL连接;值为ture时,启动TLS / SSL连接

    connectTimeoutMS:连接超时值,默认永不超时。单位毫秒。

    socketTimeoutMS:套接字超时值,默认永不超时。单位毫秒。

  3)Connection Pool Options

    maxPoolSize:连接池最大连接数,默认值为100。

    minPoolSize:连接池最小连接数,默认值为0。

  示例:

  mongodb://test:cnki2016@192.168.22.26:27017/DBFIRST?maxPoolSize=100;minPoolSize=10

1.2 方法

1)public override sealed void DropDatabase(string name, CancellationToken cancellationToken = null)

删除数据库

参数:

  name:数据库名称

  cancellationToken:传播有关应取消操作的通知。

2)public override sealed IMongoDatabase GetDatabase(string name, MongoDatabaseSettings settings = null);

获得数据库

参数:

  name:数据库名称

  settings:数据库设置

2 IMongoDatabase

1)void CreateCollection(string name, CreateCollectionOptions options = null, CancellationToken cancellationToken = null)

创建集合

参数:

  name:集合名称

  Options:创建集合时的待选参数

  cancellationToken:传播有关应取消操作的通知

2)void DropCollection(string name, CancellationToken cancellationToken = null);

删除集合

参数:

  name:集合名称

  cancellationToken:传播有关应取消操作的通知

3)IMongoCollection<TDocument> GetCollection<TDocument>(string name, MongoCollectionSettings settings = null)

获得集合

参数:

  TDocument:文档类型

  name:集合名称

  settings:数据库设置

4)void RenameCollection(string oldName, string newName, RenameCollectionOptions options = null, CancellationToken cancellationToken = null)

重命名集合

参数:

  oldName:集合旧的名称

  newName:集合新名称

  options:重命名时的设置参数

  cancellationToken:传播有关应取消操作的通知

3 IMongoCollection

1)DeleteResult DeleteMany(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = null)

删除多个文档,将过滤出的文档全部删除

参数:

  TDocument:文档类型

  filter:过滤器

  cancellationToken:传播有关应取消操作的通知

2) DeleteResult DeleteOne(FilterDefinition<TDocument> filter, CancellationToken cancellationToken = null)

删除一个文档,将过滤出的文档中第一个删除。

参数:

  TDocument:文档类型

  filter:过滤器

  cancellationToken:传播有关应取消操作的通知

3) void InsertMany(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = null)

插入多个文档

参数:

  TDocument:文档类型

  documents:待插入文档

  options:插入操作设置参数

  cancellationToken:传播有关应取消操作的通知

4) void InsertOne(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = null)

插入一个文档

参数:

  documents:待插入文档

  options:插入操作设置参数

  cancellationToken:传播有关应取消操作的通知

5) UpdateResult UpdateMany(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = null)

更新多个文档,将过滤出的多个文档全部更新

参数:

  TDocument:文档类型

  filter:过滤器

  update:更新过滤器

  options:插入操作设置参数

  cancellationToken:传播有关应取消操作的通知

6) UpdateResult UpdateOne(FilterDefinition<TDocument> filter, UpdateDefinition<TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = null)

更新一个文档,将过滤出的多个文档中的第一个更新

参数:

  TDocument:文档类型

  filter:过滤器

  update:更新过滤器

  options:插入操作设置参数

  cancellationToken:传播有关应取消操作的通知

7) long Count(FilterDefinition<TDocument> filter, CountOptions options = null, CancellationToken cancellationToken = null)

获得文档数量

参数:

  TDocument:文档类型

  filter:过滤器

  options:插入操作设置参数

  cancellationToken:传播有关应取消操作的通知

8) Task InsertManyAsync(IEnumerable<TDocument> documents, InsertManyOptions options = null, CancellationToken cancellationToken = null)

已异步的方式插入多个文档

参数:

  TDocument:文档类型

  documents:待插入文档

  options:插入操作设置参数

  cancellationToken:传播有关应取消操作的通知

9) Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = null)

以异步方式插入一个文档

参数:

  TDocument:文档类型

  documents:待插入文档

  options:插入操作设置参数

  cancellationToken:传播有关应取消操作的通知

10)IBsonSerializer<TDocument> DocumentSerializer { get; }

获得文档序列化器

11)IAsyncCursor<TResult> Aggregate<TResult>(PipelineDefinition<TDocument, TResult> pipeline, AggregateOptions options = null, CancellationToken cancellationToken = null)

聚集操作

参数:

  TResult:返回结果类型

  TDocument:输入文档类型

  pipeline:管道

  options :设置参数

  cancellationToken :取消标记

4 IMongoCollectionExtensions

1)public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOptions options = null)

找到文档

参数:

  TDocument:文档类型

  collection:集合

  filter:查找条件

  options:查找操作设置参数

2)public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, FindOptions options = null)

找到文档

参数:

  TDocument:文档类型

  collection:集合

  filter:查找条件

  options:查找操作设置参数

5 DeleteResult 

1)public abstract long DeletedCount { get; }

获得删除的条数,如果IsAcknowledged的值为false,将抛出异常

2)public abstract bool IsAcknowledged { get; }

结果是否被承认

6 UpdateResult 

1)public abstract bool IsAcknowledged { get; }

结果是否被承认

2)public abstract bool IsModifiedCountAvailable { get; }

是否可以获得修改的数量

3)public abstract long MatchedCount { get; }

匹配到的数量

4)public abstract long ModifiedCount { get; }

修改的数量

5)public abstract BsonValue UpsertedId { get; }

获得更新插入的id

7 IFindFluent<TDocument, TDocument> 继承了IAsyncCursorSource<TProjection>

1)IFindFluent<TDocument, TProjection> Limit(int? limit)

限制取出的文档数量

参数:

  TDocument:文档类型

  TProjection:投影类型,如果没有投影那么其类型和TDocument相同

  limit:取出文档数量

2)IFindFluent<TDocument, TNewProjection> Project<TNewProjection>(ProjectionDefinition<TDocument, TNewProjection> projection)

对找到的文档进行投影操作

参数:

  TDocument:文档类型

  TNewProjection:投影类型,如果没有投影那么其类型和TDocument相同

  projection:投影

3)IFindFluent<TDocument, TProjection> Skip(int? skip)

跳过一定数量的文档

参数:

  TDocument:文档类型

  TProjection:投影类型,如果没有投影那么其类型和TDocument相同

  skip:跳过的条数

4)IFindFluent<TDocument, TProjection> Sort(SortDefinition<TDocument> sort)

对找到的文档排序

参数:

  TDocument:文档类型

  TProjection:投影类型,如果没有投影那么其类型和TDocument相同

  sort:排序定义

8 IFindFluentExtensions

public static TProjection First<TDocument, TProjection>(this IFindFluent<TDocument, TProjection> find, CancellationToken cancellationToken = null)

获得找到的第一个元素。

参数:

  TDocument:文档类型

  TProjection:投影类型,如果没有投影那么其类型和TDocument相同

  find:查找条件

  cancellationToken:传播有关应取消操作的通知

9 IAsyncCursorSourceExtensions

public static List<TDocument> ToList<TDocument>(this IAsyncCursorSource<TDocument> source, CancellationToken cancellationToken = null)

将IAsyncCursorSource<TDocument> source转换为List<TDocument>

参数:

  TDocument:文档类型

  source:待转换集合

  cancellationToken:传播有关应取消操作的通知

-----------------------------------------------------------------------------------------

转载与引用请注明出处。

时间仓促,水平有限,如有不当之处,欢迎指正。

.NET MongoDB Driver 2.2 API注释的更多相关文章

  1. c# MongoDB Driver 官方教程翻译

    先贴官方文档地址:http://mongodb.github.io/mongo-csharp-driver/2.5/getting_started/quick_tour/ 安装部分很简单,nuget搜 ...

  2. 基于MongoDB.Driver的扩展

    由于MongoDB.Driver中的Find方法也支持表达式写法,结合[通用查询设计思想]这篇文章中的查询思想,个人基于MongoDB扩展了一些常用的方法. 首先我们从常用的查询开始,由于MongoD ...

  3. MongoDB.Driver 2.4以上版本 在.NET中的基本操作

    MongoDB.Driver是操作mongo数据库的驱动,最近2.0以下版本已经从GitHub和Nuget中移除了,也就是说.NET Framework4.0不再能从官方获取到MongoDB的驱动了, ...

  4. MongoDB Driver 简单的CURD

    c#中我们可以使用MongoDB.Driver驱动进行对MongoDB数据库的增删改查. 首先需要在NuGet中安装驱动 安装完毕后会发现会有三个引用 其中 MongoDB.Driver和MongoD ...

  5. MongoDB系列:五、MongoDB Driver使用正确的姿势连接复制集

    MongoDB复制集(Replica Set)通过存储多份数据副本来保证数据的高可靠,通过自动的主备切换机制来保证服务的高可用.但需要注意的时,连接副本集的姿势如果不对,服务高可用将不复存在. 使用复 ...

  6. C# mongoDB Driver 使用对象方式查询语法大全

    #region 查询方法 /// <summary> /// 获取单个对象 /// </summary> /// <typeparam name="T" ...

  7. php MongoDB driver 查询实例

    //是否只查mx $mx_on_switch = I("post.mx_on_switch"); //mx模糊查询 $mx_vague_check = I("post.m ...

  8. PHP7 - MongoDB Driver 使用心得

    php7 只能使用Mongodb driver来驱动mongodb. 使用Mongodb Driver连接数据库 刚开始使用Mongodb Driver的时候我是拒绝的.查看官方文档只看到一排的类和不 ...

  9. MongoDB入门及 c# .netcore客户端MongoDB.Driver使用

    MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系 ...

随机推荐

  1. SSL/TLS通信

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/31 复习基本概念 对称密码:加密和解密使用同一密匙. 公钥密码: ...

  2. bzoj 3207: 花神的嘲讽计划Ⅰ

    Description 背景 花神是神,一大癖好就是嘲讽大J,举例如下: "哎你傻不傻的![hqz:大笨J]" "这道题又被J屎过了!!" "J这程序 ...

  3. mysql case when group by实例

    mysql 中类似php switch case 的语句. select xx字段, case 字段 when 条件1 then 值1 when 条件2 then 值2 else 其他值 END 别名 ...

  4. gitlab 本地 定时备份

    =============================================== 20171015_第1次修改                       ccb_warlock === ...

  5. Extjs 取消backspace事件

    Ext.getDoc().on('keydown',function(e){ if(e.getKey() == 8 && e.getTarget().type =='text' &am ...

  6. 开发中关于Git那些事(续:Git变基)

    其实上一篇写的内容仅仅是Git的冰山一角,如果你认为Git就是简简单单的几行命令,那只能说明你还没有真正了解Git这个强大的内容寻址文件系统.这篇文章,还是接着介绍一些实用但是很少有人知晓的一些命令, ...

  7. Java的演化-Java8实战笔记

    一个语言要想一直有活力,它也需要跟随着时代的变化去进步,Java作为一个古老的语言,它其实有太多的历史包袱,在改变的过程中需要考虑很多,但是它也在慢慢的演变,巩固自己的城墙,不让自己被遗忘在历史中(不 ...

  8. 在IIS使用localDB

    项目使用localdb来作为本机测试数据库,发布到本机IIS后项目却链接不到数据库,查看windows日志为如下错误 "无法获取本地应用程序数据路径.很可能是因为未加载用户配置文件.如果在 ...

  9. Sticky Footer 绝对底部的两种套路

    最近面了好几个前端,工作经验有高有低,居然都不知道绝对底部是什么,也没有人能说出一种实现方式,让我不禁感慨前端领域的良莠不齐 绝对底部,或者说 Sticky Footer,是一种古老且经典的页面效果: ...

  10. Vue 爬坑之路(五)—— 组件进阶

    组件(Component)是 Vue.js 最强大的功能之一,之前的文章都只是用到了基本的封装功能,这次将介绍一些更强大的扩展. 一.基本用法 在使用 vue-cli 创建的项目中,组件的创建非常方便 ...