# Class: MongoClient

## vertx-mongo-js/mongo_client~ MongoClient

#### new MongoClient()

A Vert.x service used to interact with MongoDB server instances.

Source:
  - vertx-mongo-js/mongo_client.js, line 39

### Methods

#### bulkWrite(collection, operations, resultHandler) → {MongoClient}

Execute a bulk operation. Can insert, update, replace, and/or delete multiple documents with one request.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`operations` | Array.<Object> | the operations to execute
`resultHandler` | function | will be called with a MongoClientBulkWriteResult when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 355

##### Returns:

Type
  MongoClient

#### bulkWriteWithOptions(collection, operations, bulkWriteOptions, resultHandler) → {MongoClient}

Execute a bulk operation with the specified write options. Can insert, update, replace, and/or delete multiple documents with one request.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`operations` | Array.<Object> | the operations to execute
`bulkWriteOptions` | Object | the write options
`resultHandler` | function | will be called with a MongoClientBulkWriteResult when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 380

##### Returns:

Type
  MongoClient

#### close()

Close the client and release its resources

Source:
  - vertx-mongo-js/mongo_client.js, line 1147

#### count(collection, query, resultHandler) → {MongoClient}

Count matching documents in a collection.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match documents
`resultHandler` | function | will be provided with the number of matching documents

Source:
  - vertx-mongo-js/mongo_client.js, line 668

##### Returns:

Type
  MongoClient

#### createCollection(collectionName, resultHandler) → {MongoClient}

Create a new collection

##### Parameters:

Name | Type | Description
--- | --- | ---
`collectionName` | string | the name of the collection
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 878

##### Returns:

Type
  MongoClient

#### createIndex(collection, key, resultHandler) → {MongoClient}

Creates an index.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`key` | Object | A document that contains the field and value pairs where the field is the index key and the value describes the type of index for that field. For an ascending index on a field, specify a value of 1; for descending index, specify a value of -1.
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 944

##### Returns:

Type
  MongoClient

#### createIndexWithOptions(collection, key, options, resultHandler) → {MongoClient}

Creates an index.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`key` | Object | A document that contains the field and value pairs where the field is the index key and the value describes the type of index for that field. For an ascending index on a field, specify a value of 1; for descending index, specify a value of -1.
`options` | Object | the options for the index
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 968

##### Returns:

Type
  MongoClient

#### distinct(collection, fieldName, resultClassname, resultHandler) → {MongoClient}

Gets the distinct values of the specified field name. Return a JsonArray containing distinct values (eg: [ 1 , 89 ])

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`fieldName` | string | the field name
`resultClassname` | string |
`resultHandler` | function | will be provided with array of values.

Source:
  - vertx-mongo-js/mongo_client.js, line 1061

##### Returns:

Type
  MongoClient

#### distinctBatch(collection, fieldName, resultClassname) → {ReadStream}

Gets the distinct values of the specified field name. This method use batchCursor for returning each found value. Each value is a json fragment with fieldName key (eg: {"num": 1}).

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`fieldName` | string | the field name
`resultClassname` | string |

Source:
  - vertx-mongo-js/mongo_client.js, line 1112

##### Returns:

a emitting json fragments

Type
  ReadStream

#### distinctBatchWithQuery(collection, fieldName, resultClassname, query, batchSize) → {ReadStream}

Gets the distinct values of the specified field name filtered by specified query. This method use batchCursor for returning each found value. Each value is a json fragment with fieldName key (eg: {"num": 1}).

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`fieldName` | string | the field name
`resultClassname` | string |
`query` | Object | the query
`batchSize` | number | the number of documents to load in a batch

Source:
  - vertx-mongo-js/mongo_client.js, line 1132

##### Returns:

a emitting json fragments

Type
  ReadStream

#### distinctWithQuery(collection, fieldName, resultClassname, query, resultHandler) → {MongoClient}

Gets the distinct values of the specified field name filtered by specified query. Return a JsonArray containing distinct values (eg: [ 1 , 89 ])

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`fieldName` | string | the field name
`resultClassname` | string |
`query` | Object | the query
`resultHandler` | function | will be provided with array of values.

Source:
  - vertx-mongo-js/mongo_client.js, line 1087

##### Returns:

Type
  MongoClient

#### dropCollection(collection, resultHandler) → {MongoClient}

Drop a collection

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 921

##### Returns:

Type
  MongoClient

#### dropIndex(collection, indexName, resultHandler) → {MongoClient}

Drops the index given its name.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`indexName` | string | the name of the index to remove
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 1013

##### Returns:

Type
  MongoClient

#### find(collection, query, resultHandler) → {MongoClient}

Find matching documents in the specified collection

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match documents
`resultHandler` | function | will be provided with list of documents

Source:
  - vertx-mongo-js/mongo_client.js, line 403

##### Returns:

Type
  MongoClient

#### findBatch(collection, query) → {ReadStream}

Find matching documents in the specified collection. This method use batchCursor for returning each found document.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match documents

Source:
  - vertx-mongo-js/mongo_client.js, line 426

##### Returns:

a emitting found documents

Type
  ReadStream

#### findBatchWithOptions(collection, query, options) → {ReadStream}

Find matching documents in the specified collection, specifying options. This method use batchCursor for returning each found document.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match documents
`options` | Object | options to configure the find

Source:
  - vertx-mongo-js/mongo_client.js, line 467

##### Returns:

a emitting found documents

Type
  ReadStream

#### findOne(collection, query, fields, resultHandler) → {MongoClient}

Find a single matching document in the specified collection

This operation might change _id field of query parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | the query used to match the document
`fields` | Object | the fields
`resultHandler` | function | will be provided with the document, if any

Source:
  - vertx-mongo-js/mongo_client.js, line 486

##### Returns:

Type
  MongoClient

#### findOneAndDelete(collection, query, resultHandler) → {MongoClient}

Find a single matching document in the specified collection and delete it.

This operation might change _id field of query parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | the query used to match the document
`resultHandler` | function | will be provided with the deleted document, if any

Source:
  - vertx-mongo-js/mongo_client.js, line 619

##### Returns:

Type
  MongoClient

#### findOneAndDeleteWithOptions(collection, query, findOptions, resultHandler) → {MongoClient}

Find a single matching document in the specified collection and delete it.

This operation might change _id field of query parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | the query used to match the document
`findOptions` | Object | options to configure the find
`resultHandler` | function | will be provided with the deleted document, if any

Source:
  - vertx-mongo-js/mongo_client.js, line 645

##### Returns:

Type
  MongoClient

#### findOneAndReplace(collection, query, replace, resultHandler) → {MongoClient}

Find a single matching document in the specified collection and replace it.

This operation might change _id field of query parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | the query used to match the document
`replace` | Object | the replacement document
`resultHandler` | function | will be provided with the document, if any

Source:
  - vertx-mongo-js/mongo_client.js, line 566

##### Returns:

Type
  MongoClient

#### findOneAndReplaceWithOptions(collection, query, replace, findOptions, updateOptions, resultHandler) → {MongoClient}

Find a single matching document in the specified collection and replace it.

This operation might change _id field of query parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | the query used to match the document
`replace` | Object | the replacement document
`findOptions` | Object | options to configure the find
`updateOptions` | Object | options to configure the update
`resultHandler` | function | will be provided with the document, if any

Source:
  - vertx-mongo-js/mongo_client.js, line 594

##### Returns:

Type
  MongoClient

#### findOneAndUpdate(collection, query, update, resultHandler) → {MongoClient}

Find a single matching document in the specified collection and update it.

This operation might change _id field of query parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | the query used to match the document
`update` | Object | used to describe how the documents will be updated
`resultHandler` | function | will be provided with the document, if any

Source:
  - vertx-mongo-js/mongo_client.js, line 512

##### Returns:

Type
  MongoClient

#### findOneAndUpdateWithOptions(collection, query, update, findOptions, updateOptions, resultHandler) → {MongoClient}

Find a single matching document in the specified collection and update it.

This operation might change _id field of query parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | the query used to match the document
`update` | Object | used to describe how the documents will be updated
`findOptions` | Object | options to configure the find
`updateOptions` | Object | options to configure the update
`resultHandler` | function | will be provided with the document, if any

Source:
  - vertx-mongo-js/mongo_client.js, line 540

##### Returns:

Type
  MongoClient

#### findWithOptions(collection, query, options, resultHandler) → {MongoClient}

Find matching documents in the specified collection, specifying options

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match documents
`options` | Object | options to configure the find
`resultHandler` | function | will be provided with list of documents

Source:
  - vertx-mongo-js/mongo_client.js, line 443

##### Returns:

Type
  MongoClient

#### getCollections(resultHandler) → {MongoClient}

Get a list of all collections in the database.

##### Parameters:

Name | Type | Description
--- | --- | ---
`resultHandler` | function | will be called with a list of collections.

Source:
  - vertx-mongo-js/mongo_client.js, line 899

##### Returns:

Type
  MongoClient

#### insert(collection, document, resultHandler) → {MongoClient}

Insert a document in the specified collection

This operation might change _id field of document parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`document` | Object | the document
`resultHandler` | function | result handler will be provided with the id if document didn't already have one

Source:
  - vertx-mongo-js/mongo_client.js, line 106

##### Returns:

Type
  MongoClient

#### insertWithOptions(collection, document, writeOption, resultHandler) → {MongoClient}

Insert a document in the specified collection with the specified write option

This operation might change _id field of document parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`document` | Object | the document
`writeOption` | Object | the write option to use
`resultHandler` | function | result handler will be provided with the id if document didn't already have one

Source:
  - vertx-mongo-js/mongo_client.js, line 132

##### Returns:

Type
  MongoClient

#### listIndexes(collection, resultHandler) → {MongoClient}

Get all the indexes in this collection.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 990

##### Returns:

Type
  MongoClient

#### remove(collection, query, resultHandler) → {MongoClient}

Remove matching documents from a collection

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match documents
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 691

##### Returns:

Type
  MongoClient

#### removeDocument(collection, query, resultHandler) → {MongoClient}

Remove a single matching document from a collection and return the handler with MongoClientDeleteResult result

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match document
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 808

##### Returns:

Type
  MongoClient

#### removeDocuments(collection, query, resultHandler) → {MongoClient}

Remove matching documents from a collection and return the handler with MongoClientDeleteResult result

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match documents
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 714

##### Returns:

Type
  MongoClient

#### removeDocumentsWithOptions(collection, query, writeOption, resultHandler) → {MongoClient}

Remove matching documents from a collection with the specified write option and return the handler with MongoClientDeleteResult result

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match documents
`writeOption` | Object | the write option to use
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 762

##### Returns:

Type
  MongoClient

#### removeDocumentWithOptions(collection, query, writeOption, resultHandler) → {MongoClient}

Remove a single matching document from a collection with the specified write option and return the handler with MongoClientDeleteResult result

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match document
`writeOption` | Object | the write option to use
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 856

##### Returns:

Type
  MongoClient

#### removeOne(collection, query, resultHandler) → {MongoClient}

Remove a single matching document from a collection

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match document
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 785

##### Returns:

Type
  MongoClient

#### removeOneWithOptions(collection, query, writeOption, resultHandler) → {MongoClient}

Remove a single matching document from a collection with the specified write option

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match document
`writeOption` | Object | the write option to use
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 832

##### Returns:

Type
  MongoClient

#### removeWithOptions(collection, query, writeOption, resultHandler) → {MongoClient}

Remove matching documents from a collection with the specified write option

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match documents
`writeOption` | Object | the write option to use
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 738

##### Returns:

Type
  MongoClient

#### replace(collection, query, replace, resultHandler) → {MongoClient}

Replace matching documents in the specified collection

This operation might change _id field of replace parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match the documents
`replace` | Object | all matching documents will be replaced with this
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 256

##### Returns:

Type
  MongoClient

#### replaceDocuments(collection, query, replace, resultHandler) → {MongoClient}

Replace matching documents in the specified collection and return the handler with MongoClientUpdateResult result

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match the documents
`replace` | Object | all matching documents will be replaced with this
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 280

##### Returns:

Type
  MongoClient

#### replaceDocumentsWithOptions(collection, query, replace, options, resultHandler) → {MongoClient}

Replace matching documents in the specified collection, specifying options and return the handler with MongoClientUpdateResult result

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match the documents
`replace` | Object | all matching documents will be replaced with this
`options` | Object | options to configure the replace
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 332

##### Returns:

Type
  MongoClient

#### replaceWithOptions(collection, query, replace, options, resultHandler) → {MongoClient}

Replace matching documents in the specified collection, specifying options

This operation might change _id field of replace parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match the documents
`replace` | Object | all matching documents will be replaced with this
`options` | Object | options to configure the replace
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 307

##### Returns:

Type
  MongoClient

#### runCommand(commandName, command, resultHandler) → {MongoClient}

Run an arbitrary MongoDB command.

##### Parameters:

Name | Type | Description
--- | --- | ---
`commandName` | string | the name of the command
`command` | Object | the command
`resultHandler` | function | will be called with the result.

Source:
  - vertx-mongo-js/mongo_client.js, line 1036

##### Returns:

Type
  MongoClient

#### save(collection, document, resultHandler) → {MongoClient}

Save a document in the specified collection

This operation might change _id field of document parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`document` | Object | the document
`resultHandler` | function | result handler will be provided with the id if document didn't already have one

Source:
  - vertx-mongo-js/mongo_client.js, line 55

##### Returns:

Type
  MongoClient

#### saveWithOptions(collection, document, writeOption, resultHandler) → {MongoClient}

Save a document in the specified collection with the specified write option

This operation might change _id field of document parameter

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`document` | Object | the document
`writeOption` | Object | the write option to use
`resultHandler` | function | result handler will be provided with the id if document didn't already have one

Source:
  - vertx-mongo-js/mongo_client.js, line 81

##### Returns:

Type
  MongoClient

#### update(collection, query, update, resultHandler) → {MongoClient}

Update matching documents in the specified collection

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match the documents
`update` | Object | used to describe how the documents will be updated
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 156

##### Returns:

Type
  MongoClient

#### updateCollection(collection, query, update, resultHandler) → {MongoClient}

Update matching documents in the specified collection and return the handler with MongoClientUpdateResult result

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match the documents
`update` | Object | used to describe how the documents will be updated
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 180

##### Returns:

Type
  MongoClient

#### updateCollectionWithOptions(collection, query, update, options, resultHandler) → {MongoClient}

Update matching documents in the specified collection, specifying options and return the handler with MongoClientUpdateResult result

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match the documents
`update` | Object | used to describe how the documents will be updated
`options` | Object | options to configure the update
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 230

##### Returns:

Type
  MongoClient

#### updateWithOptions(collection, query, update, options, resultHandler) → {MongoClient}

Update matching documents in the specified collection, specifying options

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | string | the collection
`query` | Object | query used to match the documents
`update` | Object | used to describe how the documents will be updated
`options` | Object | options to configure the update
`resultHandler` | function | will be called when complete

Source:
  - vertx-mongo-js/mongo_client.js, line 205

##### Returns:

Type
  MongoClient