. NET MongoDB Driver 2.2 API Notes

Source: Internet
Author: User
Tags mongoclient mongodb driver unix domain socket ssl connection

Main content

1 mongoclient

1.1 constructor Function

1.2 Method

2 Imongodatabase

3 imongocollection

4 imongocollectionextensions

5 Deleteresult

6 Updateresult

7 Ifindfluent<tdocument, Tdocument> inherited the

8 Ifindfluentextensions

9 iasynccursorsourceextensions

Ten builders<documentinfo> Constructors

Filterdefinitionbuilder<tdocument>

Filterdefinition<tdocument>: Basic Filter

Projectiondefinitionbuilder<tdocument>

Sortdefinitionbuilder<tdocument>

Updatedefinitionbuilder<tdocument>

Bsondocument: represents a BSON document

Ibsonserializerextensions: Extended from Ibsonserializer

Bsondeserializationcontext

Aggregateoptions

1 mongoclient 1.1 constructor function

1) Public mongoclient (Mongoclientsettings settings);

Mongoclientsettings: The Mongourl function is basically the same, but Mongoclientsettings 's properties are mostly modifiable types.

2) public mongoclient (mongourl URL);

Mongourl: The connection utl is set through the constructor public mongourl (string url). Note that the properties of the Mongourl are read-only types.

3) public mongoclient (string connectionString);

ConnectionString for connection string, standard connection string style:

Mongodb://[username:[email protected]]host1[:p ort1][,host2[:p Ort2],... [, hostn[:p Ortn]] [/[database][?options]]

Parameter description:

mongodb://

Must be selected. Indicates that this link string has a standard format

Username:[email protected]

Optional. If specified, the client will attempt to log in to the specific database using these credentials

Host1

must be selected. The server connection address is specified. It determines a host name,IP address, or UNIX domain socket.

:p Ort1

Optional. The default value is 27017, which is the default value if not specified.

Hostx

Optional. You can specify as many hosts as you would, and you will specify multiple hosts, for example, to connect to the replica set.

/database

Optional. Used to verify the database name if the connection string contains username:[email protected] format for authentication credentials . If/database is not specified and the authentication credentials are included, the driver verifies the admin database

? options

Optional. Format:name=value, using & or ; separates each pair of values.

Example:mongodb://192.168.22.246,192.168.22.245:2500/?replicaset=test&connecttimeoutms=300000

1) Replica Set Option

Replicaset: Specifies the name of the replica set.

2) Connection Options

SSL: The default value is false, the TLS/SSL connection is not started, and the Tls/ssl connection is started when the value is ture

CONNECTTIMEOUTMS: Connection timeout value, default never timeout. Unit milliseconds.

SOCKETTIMEOUTMS: The socket timeout value, which never expires by default. Unit milliseconds.

3) Connection Pool Options

Maxpoolsize: Connection Pool Maximum number of connections, the default value is 100.

Minpoolsize: Connection Pool Minimum connection number, default value is 0.

Example:

Mongodb://test:[email protected]:27017/dbfirst?maxpoolsize=100;minpoolsize=10

1.2 Method

1) public override sealed void Dropdatabase (string name, CancellationToken CancellationToken = null)

Deleting a database

Parameters:

Name: Database names

CancellationToken: propagates notifications about actions that should be canceled .

2) public override sealed Imongodatabase Getdatabase (string name, mongodatabasesettings settings = null);

Get the database

Parameters:

Name: Database names

Settings: Database Settings

2 Imongodatabase

1) void CreateCollection (string name, createcollectionoptions options = null, CancellationToken CancellationToken = null)

Create a Collection

Parameters:

Name: Collection name

Options: Parameters to select when creating a collection

CancellationToken: Propagating notifications about actions that should be canceled

2) void Dropcollection (string name, CancellationToken cancellationtoken = null);

Delete Collection

Parameters:

Name: Collection name

CancellationToken: propagating notifications about actions that should be canceled

3) imongocollection<tdocument> getcollection<tdocument> (string name, mongocollectionsettings settings = Null

Get the collection

Parameters:

Tdocument: Document Type

Name: Collection name

Settings: Database Settings

4) void Renamecollection (String oldname, String newName, renamecollectionoptions options = null, CancellationToken CancellationToken = null)

Renaming collections

Parameters:

Oldname: Collection of old names

NewName: Collection New name

Options: Setting parameters when renaming

CancellationToken: propagating notifications about actions that should be canceled

3 imongocollection

1) Deleteresult Deletemany (filterdefinition<tdocument> filter, cancellationtoken cancellationtoken = null)

Delete multiple documents, delete all the filtered documents

Parameters:

Tdocument: Document Type

Filter: Filters

CancellationToken: Propagating notifications about actions that should be canceled

2) Deleteresult Deleteone (filterdefinition<tdocument> filter, cancellationtoken cancellationtoken = null)

Delete a document that will filter out the first deletion of a document.

Parameters:

Tdocument: Document Type

Filter: Filters

CancellationToken: Propagating notifications about actions that should be canceled

3) void Insertmany (ienumerable<tdocument> documents, insertmanyoptions options = null, CancellationToken CancellationToken = null)

Inserting multiple documents

Parameters:

Tdocument: Document Type

Documents: Document to be inserted

Options: Insert Action setup parameters

CancellationToken: Propagating notifications about actions that should be canceled

4) void Insertone (tdocument document, insertoneoptions options = null, CancellationToken CancellationToken = null)

Insert a document

Parameters:

Documents: Document to be inserted

Options: Insert Action setup parameters

CancellationToken: Propagating notifications about actions that should be canceled

5) Updateresult Updatemany (filterdefinition<tdocument> filter, updatedefinition<tdocument> Update, UpdateOptions options = null, CancellationToken CancellationToken = null)

Update multiple documents to update all of the filtered documents

Parameters:

Tdocument: Document Type

Filter: Filters

Update: Updating filters

Options: Insert Action setup parameters

CancellationToken: Propagating notifications about actions that should be canceled

6) Updateresult Updateone (filterdefinition<tdocument> filter, updatedefinition<tdocument> Update, UpdateOptions options = null, CancellationToken CancellationToken = null)

Updates a document that will filter out the first update in multiple documents

Parameters:

Tdocument: Document Type

Filter: Filters

Update: Updating filters

Options: Insert Action setup parameters

CancellationToken: Propagating notifications about actions that should be canceled

7) long Count (filterdefinition<tdocument> filter, countoptions options = null, CancellationToken CancellationToken = null)

Get the number of documents

Parameters:

Tdocument: Document Type

Filter: Filters

Options: Insert Action setup parameters

CancellationToken: Propagating notifications about actions that should be canceled

8) Task Insertmanyasync (ienumerable<tdocument> documents, insertmanyoptions options = null, CancellationToken CancellationToken = null)

Inserting multiple documents in an asynchronous manner

Parameters:

Tdocument: Document Type

Documents: Document to be inserted

Options: Insert Action setup parameters

CancellationToken: Propagating notifications about actions that should be canceled

9) Task Insertoneasync (tdocument document, insertoneoptions options = null, CancellationToken CancellationToken = null)

To insert a document asynchronously

Parameters:

Tdocument: Document Type

Documents: Document to be inserted

Options: Insert Action setup parameters

CancellationToken: Propagating notifications about actions that should be canceled

Ten) ibsonserializer<tdocument> Documentserializer {get;}

Get the document Serializer

One) iasynccursor<tresult> aggregate<tresult> (Pipelinedefinition<tdocument, TResult> pipeline, Aggregateoptions options = null, CancellationToken CancellationToken = null)

Aggregation operations

Parameters:

TResult: return result type

Tdocument: Enter document Type

Pipeline: Piping

Options : Setting Parameters

CancellationToken : Unmark

4 imongocollectionextensions

1) public static ifindfluent<tdocument, tdocument> find<tdocument> (This imongocollection<tdocument > Collection, Expression<func<tdocument, bool>> filter, findoptions options = null)

Find Documents

Parameters:

Tdocument: Document Type

Collection: Collection

Filter: Find Condition

Options: Find operation setup Parameters

2) public static ifindfluent<tdocument, tdocument> find<tdocument> (This imongocollection<tdocument > collection, filterdefinition<tdocument> filter, findoptions options = null)

Find Documents

Parameters:

Tdocument: Document Type

Collection: Collection

Filter: Find Condition

Options: Find operation setup Parameters

5 Deleteresult

1) public abstract long Deletedcount {get;}

gets the number of deleted bars, if The value of isacknowledged is false and an exception is thrown

2) public abstract bool Isacknowledged {get;}

Whether the result is recognized

6 Updateresult

1) public abstract bool Isacknowledged {get;}

Whether the result is recognized

2) public abstract bool Ismodifiedcountavailable {get;}

Whether the number of modifications can be obtained

3) public abstract long Matchedcount {get;}

The number of matches to

4) public abstract long Modifiedcount {get;}

Number of modifications

5) public abstract bsonvalue Upsertedid {get;}

get the ID of the update insert

7 ifindfluent<tdocument, tdocument> inherited the

1) ifindfluent<tdocument, tprojection> limit (int. limit)

Limit the number of documents taken out

Parameters:

Tdocument: Document Type

Tprojection: Projection type, if no projection then the same type and tdocument

Limit: Number of documents removed

2) Ifindfluent<tdocument, tnewprojection> project<tnewprojection> (Projectiondefinition<tdocument, Tnewprojection> projection)

To project a found document

Parameters:

Tdocument: Document Type

Tnewprojection: Projection type, if no projection then the same type and tdocument

Projection: Projection

3) ifindfluent<tdocument, tprojection> skip (int? skip)

Skip a certain number of documents

Parameters:

Tdocument: Document Type

Tprojection: Projection type, if no projection then the same type and tdocument

Skip: Number of skipped bars

4) Ifindfluent<tdocument, tprojection> sort (sortdefinition<tdocument> sort)

Sort the documents found

Parameters:

Tdocument: Document Type

Tprojection: Projection type, if no projection then the same type and tdocument

Sort: Sorting definitions

8 Ifindfluentextensions

public static Tprojection First<tdocument, tprojection> (this ifindfluent<tdocument, tprojection> find, CancellationToken CancellationToken = null)

Gets the first element found.

Parameters:

Tdocument: Document Type

Tprojection: Projection type, if no projection then the same type and tdocument

Find: Search criteria

CancellationToken: Propagating notifications about actions that should be canceled

9 Iasynccursorsourceextensions

public static list<tdocument> tolist<tdocument> (this iasynccursorsource<tdocument> source, CancellationToken CancellationToken = null)

will be Iasynccursorsource<tdocument> source to list<tdocument>

Parameters:

Tdocument: Document Type

Source: The collection to be converted

CancellationToken: Propagating notifications about actions that should be canceled

-----------------------------------------------------------------------------------------

Reprint and quote please specify the source.

Time haste, the level is limited, if has the improper place, welcome correction.

. NET MongoDB Driver 2.2 API Notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.