.NET MongoDB Driver 2.2 API注释
主要内容
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注释的更多相关文章
- c# MongoDB Driver 官方教程翻译
先贴官方文档地址:http://mongodb.github.io/mongo-csharp-driver/2.5/getting_started/quick_tour/ 安装部分很简单,nuget搜 ...
- 基于MongoDB.Driver的扩展
由于MongoDB.Driver中的Find方法也支持表达式写法,结合[通用查询设计思想]这篇文章中的查询思想,个人基于MongoDB扩展了一些常用的方法. 首先我们从常用的查询开始,由于MongoD ...
- MongoDB.Driver 2.4以上版本 在.NET中的基本操作
MongoDB.Driver是操作mongo数据库的驱动,最近2.0以下版本已经从GitHub和Nuget中移除了,也就是说.NET Framework4.0不再能从官方获取到MongoDB的驱动了, ...
- MongoDB Driver 简单的CURD
c#中我们可以使用MongoDB.Driver驱动进行对MongoDB数据库的增删改查. 首先需要在NuGet中安装驱动 安装完毕后会发现会有三个引用 其中 MongoDB.Driver和MongoD ...
- MongoDB系列:五、MongoDB Driver使用正确的姿势连接复制集
MongoDB复制集(Replica Set)通过存储多份数据副本来保证数据的高可靠,通过自动的主备切换机制来保证服务的高可用.但需要注意的时,连接副本集的姿势如果不对,服务高可用将不复存在. 使用复 ...
- C# mongoDB Driver 使用对象方式查询语法大全
#region 查询方法 /// <summary> /// 获取单个对象 /// </summary> /// <typeparam name="T" ...
- php MongoDB driver 查询实例
//是否只查mx $mx_on_switch = I("post.mx_on_switch"); //mx模糊查询 $mx_vague_check = I("post.m ...
- PHP7 - MongoDB Driver 使用心得
php7 只能使用Mongodb driver来驱动mongodb. 使用Mongodb Driver连接数据库 刚开始使用Mongodb Driver的时候我是拒绝的.查看官方文档只看到一排的类和不 ...
- MongoDB入门及 c# .netcore客户端MongoDB.Driver使用
MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系 ...
随机推荐
- vue 回到顶部的小问题
今天在用vue项目中,实现回到顶部功能的时候,我写了一个backTop组件,接下来需要通过监听window.scroll事件来控制这个组件显示隐藏 因为可能会有其他的组件会用到这样的逻辑,所以将此功能 ...
- 《MYSQL》----字符串的复杂函数,检索的七-天-排-重
接到了一个新的需求,拿到需求的时候瞬间有点头大,因为实在是有些棘手. 我们这个系统本身是个接口系统,总接口数大概在200个左右.外部会有很多用户在 不同的时间拿着不同参数去调我们的这些接口,用户的调集 ...
- 关于java字节流的read()方法返回值为int的思考
我们都知道java中io操作分为字节流和字符流,对于字节流,顾名思义是按字节的方式读取数据,所以我们常用字节流来读取二进制流(如图片,音乐 等文件).问题是为什么字节流中定义的read()方法返回值为 ...
- linux编译php gd扩展
1 安装gd的依赖包 yum -y install gd gd2 gd-devel gd2-devel zlib freetype 2 安装jpeg: wget http://www.ijg.org/ ...
- ffempg支持文件解码
在做一个数据通道 要求有两个 1.支持打开实时流,解码得到图片 2.支持打开视频文件,得到解码图片 第一个要求前任已经实现 bool FfmpegStreamChr::Open(const char ...
- celery出现警告或异常的解决方式
做个笔记,记录下使用celery踩过的坑,不定期更新. warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED)) 我用的是Flask,所以在Fl ...
- 腾讯WeTest发布《2017中国移动游戏质量白皮书》,专注手游品质提升
1月8日,腾讯质量开放平台WeTest正式发布<2017中国移动游戏质量白皮书>. 刚刚过去的这一年,市场逐渐成熟,中国移动互联网由增量市场转向存量市场.中国移动游戏市场急剧变化,真正的精 ...
- TurnipBit口袋编程计算机:和孩子一起DIY许愿的流星
听说对着流星许愿,许的愿望都会实现,虽然不知道这个说法是不是真的,但是流星还是很好看的,为了能一直看到流星,今天就自己做一个流星保存下来,想什么时候看,就什么时候看. 首先需要想象一下流星是什么样子的 ...
- TurnipBit:DIY音乐盒教程实例
一款可以自己DIY的音乐盒,要什么曲子,就自己谱曲啦!为他(她)制作一首他喜欢的音乐,来代表您的心意,也可以让他自己来制作他最爱的音乐哦!更可以带孩子一起体验谱写欢快的音乐. 最近发现一很好玩的中国式 ...
- angular4.0中form表单双向数据绑定正确姿势
issue:用[(ngModel)]="property"指令双向数据绑定,报错. reason1:使用ngModel绑定数据需要注入FormsModule模块,在app.modu ...