1. 程式人生 > >.NET MongoDB Driver 2.2 API註釋

.NET MongoDB Driver 2.2 API註釋

時間 一個 參數說明 標準 排序 登陸 min span 第一個元素

主要內容

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:[email protected]: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> 繼承了

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註釋