# Class: MongoClient

## vertx-mongo-js/mongo_client~ MongoClient

#### new MongoClient()

  A Vert.x service used to interact with MongoDB server instances.
  Source:
    - mongo_client.js, line 32

### Methods

#### close()

  Close the client and release its resources
  Source:
    - mongo_client.js, line 511

#### 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:
    - mongo_client.js, line 309

  ##### 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:
    - mongo_client.js, line 425

  ##### 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:
    - mongo_client.js, line 468

  ##### 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:
    - mongo_client.js, line 238

  ##### Returns:

  Type
    MongoClient

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

  Find a single matching document in the specified collection

  ##### 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:
    - mongo_client.js, line 286

  ##### 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:
    - mongo_client.js, line 262

  ##### 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:
    - mongo_client.js, line 446

  ##### Returns:

  Type
    MongoClient

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

  Insert a document in the specified collection

  ##### 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:
    - mongo_client.js, line 93

  ##### Returns:

  Type
    MongoClient

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

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

  ##### 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:
    - mongo_client.js, line 117

  ##### 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:
    - mongo_client.js, line 332

  ##### 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:
    - mongo_client.js, line 379

  ##### 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:
    - mongo_client.js, line 403

  ##### 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:
    - mongo_client.js, line 356

  ##### Returns:

  Type
    MongoClient

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

  Replace matching documents in the specified collection

  ##### 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:
    - mongo_client.js, line 190

  ##### Returns:

  Type
    MongoClient

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

  Replace matching documents in the specified collection, specifying options

  ##### 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:
    - mongo_client.js, line 215

  ##### 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:
    - mongo_client.js, line 491

  ##### Returns:

  Type
    MongoClient

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

  Save a document in the specified collection

  ##### 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:
    - mongo_client.js, line 46

  ##### Returns:

  Type
    MongoClient

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

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

  ##### 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:
    - mongo_client.js, line 70

  ##### 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:
    - mongo_client.js, line 141

  ##### 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:
    - mongo_client.js, line 166

  ##### Returns:

  Type
    MongoClient