Class Collection
Represents MongoDB collections which allows to execute queries and perform CRUD operations
Inherited Members
Namespace: NFX.DataAccess.MongoDB.Connector
Assembly: NFX.MongoDB.dll
Syntax
public sealed class Collection : DisposableObject, IDisposable, INamed
Properties
Database
Declaration
public Database Database { get; }
Property Value
| Type | Description |
|---|---|
| Database |
FullName
Returns full name of this collection: database.collection
Declaration
public string FullName { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Name
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| System.String |
Server
Declaration
public ServerNode Server { get; }
Property Value
| Type | Description |
|---|---|
| ServerNode |
Methods
Count(Query, Int32, Int32, Object)
Performs server-side count over cursor
Declaration
public long Count(Query query = null, int limit = -1, int skip = -1, object hint = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Query | query | Optional. A query that selects which documents to count in a collection |
| System.Int32 | limit | Optional. The maximum number of matching documents to return |
| System.Int32 | skip | Optional. The number of matching documents to skip before returning results |
| System.Object | hint | Optional. The index to use. Specify either the index name as a string or the index specification document. |
Returns
| Type | Description |
|---|---|
| System.Int64 | Count |
Delete(DeleteEntry[])
Deletes documents from the server. Inspect CRUDResult for write errors and docs affected/matched
Declaration
public CRUDResult Delete(params DeleteEntry[] deletes)
Parameters
| Type | Name | Description |
|---|---|---|
| DeleteEntry[] | deletes |
Returns
| Type | Description |
|---|---|
| CRUDResult |
DeleteOne(Query)
Deletes 1 document from the server. Inspect CRUDResult for write errors and docs affected/matched
Declaration
public CRUDResult DeleteOne(Query query)
Parameters
| Type | Name | Description |
|---|---|---|
| Query | query |
Returns
| Type | Description |
|---|---|
| CRUDResult |
Destructor()
Declaration
protected override void Destructor()
Overrides
Drop()
Drops the collection from the server with all of its data and disposes the Collection object
Declaration
public void Drop()
Find(Query, Int32, Int32, BSONDocument)
Finds all documents that match the supplied query, optionally skipping some. Fetches only fetchBy at once, then lazily fetches via cursor
Declaration
public Cursor Find(Query query, int skipCount = 0, int fetchBy = 0, BSONDocument selector = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Query | query | Query to match against |
| System.Int32 | skipCount | How many document sto skip at the beginning |
| System.Int32 | fetchBy | The size of fetch block |
| BSONDocument | selector | Optional field mapping document like: {"field_name": 1} |
Returns
| Type | Description |
|---|---|
| Cursor | An iterable cursor |
FindAndFetchAll(Query, Int32, Int32, Int32, BSONDocument)
Finds all documents that match the supplied query, optionally skipping some. Fetches and returns all documents as a list. Be careful not to fetch too many
Declaration
public List<BSONDocument> FindAndFetchAll(Query query, int skipCount = 0, int cursorFetchLimit = 0, int fetchBy = 0, BSONDocument selector = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Query | query | Query to match against |
| System.Int32 | skipCount | How many documents to skip at the beginning |
| System.Int32 | cursorFetchLimit | Impose a limit on total number of fetched docs |
| System.Int32 | fetchBy | Size of fetch block |
| BSONDocument | selector | Optional field mapping document like: {"field_name": 1} |
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<BSONDocument> | A list of documents (may be empty) |
FindOne(Query, BSONDocument)
Finds a document that satisfied query or null
Declaration
public BSONDocument FindOne(Query query, BSONDocument selector = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Query | query | |
| BSONDocument | selector |
Returns
| Type | Description |
|---|---|
| BSONDocument |
Insert(BSONDocument[])
Inserts documents on the server. Inspect CRUDResult for write errors and docs affected/matched
Declaration
public CRUDResult Insert(params BSONDocument[] documents)
Parameters
| Type | Name | Description |
|---|---|---|
| BSONDocument[] | documents |
Returns
| Type | Description |
|---|---|
| CRUDResult |
Save(BSONDocument)
Updates or inserts 1 document on the server. Inspect CRUDResult for write errors and docs affected/matched
Declaration
public CRUDResult Save(BSONDocument document)
Parameters
| Type | Name | Description |
|---|---|---|
| BSONDocument | document |
Returns
| Type | Description |
|---|---|
| CRUDResult |
Update(UpdateEntry[])
Updates documents on the server. Inspect CRUDResult for write errors and docs affected/matched
Declaration
public CRUDResult Update(params UpdateEntry[] updates)
Parameters
| Type | Name | Description |
|---|---|---|
| UpdateEntry[] | updates |
Returns
| Type | Description |
|---|---|
| CRUDResult |