.NET MongoDB Driver 2.2 API注釋

來源:互聯網
上載者:User

標籤:預設值   family   ini   res   cee   cli   異常   輸入   documents   

主要內容

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:[email protected]]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

參數說明:

  mongodb://

    必選。指明此連結字串具有標準格式

  username:[email protected]

    可選。如果指定,用戶端將嘗試使用這些憑證登陸到具體的資料庫

  host1

    必選。指定了伺服器串連地址。它確定了一個主機名稱,IP地址,或UNIX域通訊端。

  :port1

    可選。預設值為27017,如果未指定則為預設值。

  hostX

    可選。你可以指定儘可能多的主機,您將指定多個主機,例如,串連到複本集。

  /database

    可選。用於驗證的資料庫名稱,如果連接字串包含username:[email protected]格式的身分識別驗證憑據。如果沒有指定/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注釋

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.