主要内容

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. chown 命令详解

    chown 作用:改变某个文件或目录的所有者和所属的组, 该命令可以向某个用户授权,使该用户编程指定文件的所有者或者改变文件的所属组, 用户可以是用户或者是用户ID, 用户组可以是组名或者租ID,   ...

  2. Linux第九讲随笔 -进程管理 、ps aux 、

    Linux第九讲1,进程管理 Linux在执行每一个程序时,就会在内存中为这个程序建立一个进程,以便让内核可以管理这个运行中的进程,进程是系统分配各种资源,进程调度的基本单位. 怎么查看进程 一.ps ...

  3. Socket相关概念

    lsocket的英文原义是“孔”或“插座”.作为进程通信机制,取后一种意思.通常也称作“套接字”,用于描述IP地址和端口,是一个通信链的句柄.(其实就是两个程序通信用的.) lsocket非常类似于电 ...

  4. 鸟哥的linux私房菜学习-(二)VMware虚拟机及linux系统安装过程

    一.安装虚拟机 1.虚拟机常用版本及注册码地址:https://pan.baidu.com/s/1dFnkBrN#list/path=%2FSoftware%20Big%2FVMware%20Work ...

  5. Extjs入门-grid

    function rowdblclickFn(grid, rowIndex, e){//双击事件              var row = grid.store.getById(grid.stor ...

  6. ubuntu16编译安装mysql5.7

    安装环境: linux版本: ubuntu-16.04.3-desktop-amd64 mysql版本:mysql-boost-5.7.20.tar.gz 下载地址:https://dev.mysql ...

  7. [js高手之路] vue系列教程 - 绑定class与行间样式style(6)

    一.绑定class属性的方式 1.通过数组的方式,为元素绑定多个class <style> .red { color:red; /*color:#ff8800;*/ } .bg { bac ...

  8. ElfJS从入门到精通(一)

    介绍 Elf.js是一个简洁的高效的JavaScript框架.它不仅高度重视用户的体验,也高度重视开发者的体验.在实现当今主流技术的同时,以尽可能原生态的形式展现出来.在如今花样繁多的框架中,你是否感 ...

  9. angular4.0使用sass

    一.为什么选择sass为了更好的管理代码,我们需要可以定义变量,同时可以使用函数的样式工具,比如定义公用color.bg.显然css无法满足需求.现在市面上常用的是sass.less.经过比较,我选择 ...

  10. JDK中AbstractQueuedSynchronizer应用解析

    这个类首先是一个抽象类,定义了一个模板,很多java同步相关的类(ReetrantLock.Semaphore.CountDownLatch等)都是基于AbstractQueuedSynchroniz ...