主要内容

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. 安装lamp代码

    tar -zxvf mysqladdUser mysql -s /sbin/nologinmv mysql /usr/local/mysql (改目录下直接存储bin docs等目录)mkdir -p ...

  2. (一)DOM 常用操作 —— “查找”节点

    在 DOM 树中,如果想要操作一个节点,那么首先要"查找"到这个节点.查找节点的方法由 Document 接口定义,而该接口由 JavaScript 中的 document 对象实 ...

  3. centos7 卸载home 扩大root空间

    =============================================== 2017/11/1_第1次修改                       ccb_warlock == ...

  4. JMeter参数化实现

     参数化:指对每次发起的请求,参数名称相同,参数值进行替换,如登录三次系统,每次用不同的用户名和密码. 1.1.1. 从csv文件读取(CSV Data Set Config) 步骤: 1)新建一个文 ...

  5. python核心编写视频笔记--模块的导入

    1. 模块的重新导入 有这样的一种情况:我们首先创建了一个.py文件,输入模块代码.保存后,我们进入ipython3的环境,引入这个模块.然后再ipython3环境外修改这个模块文件,在ipython ...

  6. Numpy

    一  : 安装ipython以及用到的包介绍 # 这里我们会用到ipython解释器,本文代码在ipython下运行 Pip3 install ipython Pip3 install jupyter ...

  7. Python day02 三元运算

     type  查看数据类型.2 **32  :2的32次方 .浮点的表示类型是小数,但是小数不仅仅包括浮点 浮点数用来处理实数,即带有小数的数字 三元运算:  result = 值1 if 条件 el ...

  8. 深入剖析MSAA

    本文打算对MSAA(Multisample anti aliasing)做一个深入的讲解,包括基本的原理.以及不同平台上的实现对比(主要是PC与Mobile).为了对MSAA有个更好的理解,所以写下了 ...

  9. iOS libyuv

    libyuv是Google开源库,可用作图像数据格式的转换,比如视频流编解码时格式的转换,YUV数据转化RGB等 libyuv静态库 为了方便使用,已经将libyuv源代码打包成了iOS静态库,lib ...

  10. 浅谈JavaScript的面向对象程序设计(四)

    本文继续讲解JavaScript的面向对象程序设计.继承是面向对象语言中的一个基本概念,面向对象语言支持两种继承实现方式:接口继承和实现继承.接口继承只继承方法签名,而实现继承则继承实际的方法.但是在 ...