Package: io.vertx.groovy.ext.mongo

## [Groovy] Class MongoClient

- io.vertx.groovy.ext.mongo.MongoClient

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

- - ### Constructor Summary

    Constructors
    Constructor and description
    `MongoClient (Object delegate)`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `void` | `close()` Close the client and release its resources
    `MongoClient` | `count(String collection, Map<String, Object> query, Handler<AsyncResult<Long>> resultHandler)` Count matching documents in a collection.
    `MongoClient` | `createCollection(String collectionName, Handler<AsyncResult<Void>> resultHandler)` Create a new collection
    `static MongoClient` | `createNonShared(Vertx vertx, Map<String, Object> config)` Create a Mongo client which maintains its own data source.
    `static MongoClient` | `createShared(Vertx vertx, Map<String, Object> config, String dataSourceName)` Create a Mongo client which shares its data source with any other Mongo clients created with the same data source name
    `static MongoClient` | `createShared(Vertx vertx, Map<String, Object> config)` Like MongoClient.createShared but with the default data source name
    `MongoClient` | `dropCollection(String collection, Handler<AsyncResult<Void>> resultHandler)` Drop a collection
    `MongoClient` | `find(String collection, Map<String, Object> query, Handler<AsyncResult<List<Map<String, Object>>>> resultHandler)` Find matching documents in the specified collection
    `MongoClient` | `findOne(String collection, Map<String, Object> query, Map<String, Object> fields, Handler<AsyncResult<Map<String, Object>>> resultHandler)` Find a single matching document in the specified collection
    `MongoClient` | `findWithOptions(String collection, Map<String, Object> query, Map<String, Object> options, Handler<AsyncResult<List<Map<String, Object>>>> resultHandler)` Find matching documents in the specified collection, specifying options
    `MongoClient` | `getCollections(Handler<AsyncResult<List<String>>> resultHandler)` Get a list of all collections in the database.
    `Object` | `getDelegate()`
    `MongoClient` | `insert(String collection, Map<String, Object> document, Handler<AsyncResult<String>> resultHandler)` Insert a document in the specified collection
    `MongoClient` | `insertWithOptions(String collection, Map<String, Object> document, WriteOption writeOption, Handler<AsyncResult<String>> resultHandler)` Insert a document in the specified collection with the specified write option
    `MongoClient` | `remove(String collection, Map<String, Object> query, Handler<AsyncResult<Void>> resultHandler)` Remove matching documents from a collection
    `MongoClient` | `removeOne(String collection, Map<String, Object> query, Handler<AsyncResult<Void>> resultHandler)` Remove a single matching document from a collection
    `MongoClient` | `removeOneWithOptions(String collection, Map<String, Object> query, WriteOption writeOption, Handler<AsyncResult<Void>> resultHandler)` Remove a single matching document from a collection with the specified write option
    `MongoClient` | `removeWithOptions(String collection, Map<String, Object> query, WriteOption writeOption, Handler<AsyncResult<Void>> resultHandler)` Remove matching documents from a collection with the specified write option
    `MongoClient` | `replace(String collection, Map<String, Object> query, Map<String, Object> replace, Handler<AsyncResult<Void>> resultHandler)` Replace matching documents in the specified collection
    `MongoClient` | `replaceWithOptions(String collection, Map<String, Object> query, Map<String, Object> replace, Map<String, Object> options, Handler<AsyncResult<Void>> resultHandler)` Replace matching documents in the specified collection, specifying options
    `MongoClient` | `runCommand(String commandName, Map<String, Object> command, Handler<AsyncResult<Map<String, Object>>> resultHandler)` Run an arbitrary MongoDB command.
    `MongoClient` | `save(String collection, Map<String, Object> document, Handler<AsyncResult<String>> resultHandler)` Save a document in the specified collection
    `MongoClient` | `saveWithOptions(String collection, Map<String, Object> document, WriteOption writeOption, Handler<AsyncResult<String>> resultHandler)` Save a document in the specified collection with the specified write option
    `MongoClient` | `update(String collection, Map<String, Object> query, Map<String, Object> update, Handler<AsyncResult<Void>> resultHandler)` Update matching documents in the specified collection
    `MongoClient` | `updateWithOptions(String collection, Map<String, Object> query, Map<String, Object> update, Map<String, Object> options, Handler<AsyncResult<Void>> resultHandler)` Update matching documents in the specified collection, specifying options

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Constructor Detail

    - #### MongoClient(Object delegate)

  - ### Method Detail

    - #### void close()

      Close the client and release its resources

    - #### MongoClient count(String collection, Map<String, Object> query, Handler<AsyncResult<Long>> resultHandler)

      Count matching documents in a collection.

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `resultHandler` - will be provided with the number of matching documents

    - #### MongoClient createCollection(String collectionName, Handler<AsyncResult<Void>> resultHandler)

      Create a new collection

      Returns:
      Parameters:
        `collectionName` - the name of the collection
        `resultHandler` - will be called when complete

    - #### static MongoClient createNonShared(Vertx vertx, Map<String, Object> config)

      Create a Mongo client which maintains its own data source.

      Returns:
        the client
      Parameters:
        `vertx` - the Vert.x instance
        `config` - the configuration

    - #### static MongoClient createShared(Vertx vertx, Map<String, Object> config, String dataSourceName)

      Create a Mongo client which shares its data source with any other Mongo clients created with the same data source name

      Returns:
        the client
      Parameters:
        `vertx` - the Vert.x instance
        `config` - the configuration
        `dataSourceName` - the data source name

    - #### static MongoClient createShared(Vertx vertx, Map<String, Object> config)

      Like MongoClient.createShared but with the default data source name

      Returns:
        the client
      Parameters:
        `vertx` - the Vert.x instance
        `config` - the configuration

    - #### MongoClient dropCollection(String collection, Handler<AsyncResult<Void>> resultHandler)

      Drop a collection

      Returns:
      Parameters:
        `collection` - the collection
        `resultHandler` - will be called when complete

    - #### MongoClient find(String collection, Map<String, Object> query, Handler<AsyncResult<List<Map<String, Object>>>> resultHandler)

      Find matching documents in the specified collection

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `resultHandler` - will be provided with list of documents

    - #### MongoClient findOne(String collection, Map<String, Object> query, Map<String, Object> fields, Handler<AsyncResult<Map<String, Object>>> resultHandler)

      Find a single matching document in the specified collection

      Returns:
      Parameters:
        `collection` - the collection
        `query` - the query used to match the document
        `fields` - the fields
        `resultHandler` - will be provided with the document, if any

    - #### MongoClient findWithOptions(String collection, Map<String, Object> query, Map<String, Object> options, Handler<AsyncResult<List<Map<String, Object>>>> resultHandler)

      Find matching documents in the specified collection, specifying options

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `options` - options to configure the find (see FindOptions)
        `resultHandler` - will be provided with list of documents

    - #### MongoClient getCollections(Handler<AsyncResult<List<String>>> resultHandler)

      Get a list of all collections in the database.

      Returns:
      Parameters:
        `resultHandler` - will be called with a list of collections.

    - #### Object getDelegate()

    - #### MongoClient insert(String collection, Map<String, Object> document, Handler<AsyncResult<String>> resultHandler)

      Insert a document in the specified collection

      Returns:
      Parameters:
        `collection` - the collection
        `document` - the document
        `resultHandler` - result handler will be provided with the id if document didn't already have one

    - #### MongoClient insertWithOptions(String collection, Map<String, Object> document, WriteOption writeOption, Handler<AsyncResult<String>> resultHandler)

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

      Returns:
      Parameters:
        `collection` - the collection
        `document` - the document
        `writeOption` - the write option to use
        `resultHandler` - result handler will be provided with the id if document didn't already have one

    - #### MongoClient remove(String collection, Map<String, Object> query, Handler<AsyncResult<Void>> resultHandler)

      Remove matching documents from a collection

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `resultHandler` - will be called when complete

    - #### MongoClient removeOne(String collection, Map<String, Object> query, Handler<AsyncResult<Void>> resultHandler)

      Remove a single matching document from a collection

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match document
        `resultHandler` - will be called when complete

    - #### MongoClient removeOneWithOptions(String collection, Map<String, Object> query, WriteOption writeOption, Handler<AsyncResult<Void>> resultHandler)

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

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match document
        `writeOption` - the write option to use
        `resultHandler` - will be called when complete

    - #### MongoClient removeWithOptions(String collection, Map<String, Object> query, WriteOption writeOption, Handler<AsyncResult<Void>> resultHandler)

      Remove matching documents from a collection with the specified write option

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `writeOption` - the write option to use
        `resultHandler` - will be called when complete

    - #### MongoClient replace(String collection, Map<String, Object> query, Map<String, Object> replace, Handler<AsyncResult<Void>> resultHandler)

      Replace matching documents in the specified collection

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match the documents
        `replace` - all matching documents will be replaced with this
        `resultHandler` - will be called when complete

    - #### MongoClient replaceWithOptions(String collection, Map<String, Object> query, Map<String, Object> replace, Map<String, Object> options, Handler<AsyncResult<Void>> resultHandler)

      Replace matching documents in the specified collection, specifying options

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match the documents
        `replace` - all matching documents will be replaced with this
        `options` - options to configure the replace (see UpdateOptions)
        `resultHandler` - will be called when complete

    - #### MongoClient runCommand(String commandName, Map<String, Object> command, Handler<AsyncResult<Map<String, Object>>> resultHandler)

      Run an arbitrary MongoDB command.

      Returns:
      Parameters:
        `commandName` - the name of the command
        `command` - the command
        `resultHandler` - will be called with the result.

    - #### MongoClient save(String collection, Map<String, Object> document, Handler<AsyncResult<String>> resultHandler)

      Save a document in the specified collection

      Returns:
      Parameters:
        `collection` - the collection
        `document` - the document
        `resultHandler` - result handler will be provided with the id if document didn't already have one

    - #### MongoClient saveWithOptions(String collection, Map<String, Object> document, WriteOption writeOption, Handler<AsyncResult<String>> resultHandler)

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

      Returns:
      Parameters:
        `collection` - the collection
        `document` - the document
        `writeOption` - the write option to use
        `resultHandler` - result handler will be provided with the id if document didn't already have one

    - #### MongoClient update(String collection, Map<String, Object> query, Map<String, Object> update, Handler<AsyncResult<Void>> resultHandler)

      Update matching documents in the specified collection

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match the documents
        `update` - used to describe how the documents will be updated
        `resultHandler` - will be called when complete

    - #### MongoClient updateWithOptions(String collection, Map<String, Object> query, Map<String, Object> update, Map<String, Object> options, Handler<AsyncResult<Void>> resultHandler)

      Update matching documents in the specified collection, specifying options

      Returns:
      Parameters:
        `collection` - the collection
        `query` - query used to match the documents
        `update` - used to describe how the documents will be updated
        `options` - options to configure the update (see UpdateOptions)
        `resultHandler` - will be called when complete