io.vertx.ext.mongo

## Interface MongoClient

-     public interface MongoClient

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

  Some of the operations might change _id field of passed `JsonObject` document.

  Author:
    Tim Fox

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_DB_NAME` The name of the default database
    `static String` | `DEFAULT_POOL_NAME` The name of the default pool

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Close the client and release its resources
    `MongoClient` | `count(String collection, JsonObject 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, JsonObject config)` Create a Mongo client which maintains its own data source.
    `static MongoClient` | `createShared(Vertx vertx, JsonObject config)` Like `createShared(io.vertx.core.Vertx, JsonObject, String)` but with the default data source name
    `static MongoClient` | `createShared(Vertx vertx, JsonObject config, String dataSourceName)` Create a Mongo client which shares its data source with any other Mongo clients created with the same data source name
    `MongoClient` | `distinct(String collection, String fieldName, String resultClassname, Handler<AsyncResult<JsonArray>> resultHandler)` Gets the distinct values of the specified field name.
    `MongoClient` | `distinctBatch(String collection, String fieldName, String resultClassname, Handler<AsyncResult<JsonObject>> resultHandler)` Gets the distinct values of the specified field name.
    `MongoClient` | `dropCollection(String collection, Handler<AsyncResult<Void>> resultHandler)` Drop a collection
    `MongoClient` | `find(String collection, JsonObject query, Handler<AsyncResult<List<JsonObject>>> resultHandler)` Find matching documents in the specified collection
    `MongoClient` | `findBatch(String collection, JsonObject query, Handler<AsyncResult<JsonObject>> resultHandler)` Find matching documents in the specified collection.
    `MongoClient` | `findBatchWithOptions(String collection, JsonObject query, FindOptions options, Handler<AsyncResult<JsonObject>> resultHandler)` Find matching documents in the specified collection, specifying options.
    `MongoClient` | `findOne(String collection, JsonObject query, JsonObject fields, Handler<AsyncResult<JsonObject>> resultHandler)` Find a single matching document in the specified collection
    `MongoClient` | `findWithOptions(String collection, JsonObject query, FindOptions options, Handler<AsyncResult<List<JsonObject>>> 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.
    `MongoClient` | `insert(String collection, JsonObject document, Handler<AsyncResult<String>> resultHandler)` Insert a document in the specified collection
    `MongoClient` | `insertWithOptions(String collection, JsonObject document, WriteOption writeOption, Handler<AsyncResult<String>> resultHandler)` Insert a document in the specified collection with the specified write option
    `MongoClient` | `remove(String collection, JsonObject query, Handler<AsyncResult<Void>> resultHandler)` Deprecated.
    `MongoClient` | `removeDocument(String collection, JsonObject query, Handler<AsyncResult<MongoClientDeleteResult>> resultHandler)` Remove a single matching document from a collection and return the handler with MongoClientDeleteResult result
    `MongoClient` | `removeDocuments(String collection, JsonObject query, Handler<AsyncResult<MongoClientDeleteResult>> resultHandler)` Remove matching documents from a collection and return the handler with MongoClientDeleteResult result
    `MongoClient` | `removeDocumentsWithOptions(String collection, JsonObject query, WriteOption writeOption, Handler<AsyncResult<MongoClientDeleteResult>> resultHandler)` Remove matching documents from a collection with the specified write option and return the handler with MongoClientDeleteResult result
    `MongoClient` | `removeDocumentWithOptions(String collection, JsonObject query, WriteOption writeOption, Handler<AsyncResult<MongoClientDeleteResult>> resultHandler)` Remove a single matching document from a collection with the specified write option and return the handler with MongoClientDeleteResult result
    `MongoClient` | `removeOne(String collection, JsonObject query, Handler<AsyncResult<Void>> resultHandler)` Deprecated.
    `MongoClient` | `removeOneWithOptions(String collection, JsonObject query, WriteOption writeOption, Handler<AsyncResult<Void>> resultHandler)` Deprecated.
    `MongoClient` | `removeWithOptions(String collection, JsonObject query, WriteOption writeOption, Handler<AsyncResult<Void>> resultHandler)` Deprecated.
    `MongoClient` | `replace(String collection, JsonObject query, JsonObject replace, Handler<AsyncResult<Void>> resultHandler)` Deprecated.
    `MongoClient` | `replaceDocuments(String collection, JsonObject query, JsonObject replace, Handler<AsyncResult<MongoClientUpdateResult>> resultHandler)` Replace matching documents in the specified collection and return the handler with MongoClientUpdateResult result
    `MongoClient` | `replaceDocumentsWithOptions(String collection, JsonObject query, JsonObject replace, UpdateOptions options, Handler<AsyncResult<MongoClientUpdateResult>> resultHandler)` Replace matching documents in the specified collection, specifying options and return the handler with MongoClientUpdateResult result
    `MongoClient` | `replaceWithOptions(String collection, JsonObject query, JsonObject replace, UpdateOptions options, Handler<AsyncResult<Void>> resultHandler)` Deprecated.
    `MongoClient` | `runCommand(String commandName, JsonObject command, Handler<AsyncResult<JsonObject>> resultHandler)` Run an arbitrary MongoDB command.
    `MongoClient` | `save(String collection, JsonObject document, Handler<AsyncResult<String>> resultHandler)` Save a document in the specified collection
    `MongoClient` | `saveWithOptions(String collection, JsonObject document, WriteOption writeOption, Handler<AsyncResult<String>> resultHandler)` Save a document in the specified collection with the specified write option
    `MongoClient` | `update(String collection, JsonObject query, JsonObject update, Handler<AsyncResult<Void>> resultHandler)` Deprecated.
    `MongoClient` | `updateCollection(String collection, JsonObject query, JsonObject update, Handler<AsyncResult<MongoClientUpdateResult>> resultHandler)` Update matching documents in the specified collection and return the handler with MongoClientUpdateResult result
    `MongoClient` | `updateCollectionWithOptions(String collection, JsonObject query, JsonObject update, UpdateOptions options, Handler<AsyncResult<MongoClientUpdateResult>> resultHandler)` Update matching documents in the specified collection, specifying options and return the handler with MongoClientUpdateResult result
    `MongoClient` | `updateWithOptions(String collection, JsonObject query, JsonObject update, UpdateOptions options, Handler<AsyncResult<Void>> resultHandler)` Deprecated.

- - ### Field Detail

    - #### DEFAULT_POOL_NAME

          static final String DEFAULT_POOL_NAME

      The name of the default pool
      See Also:
        Constant Field Values

    - #### DEFAULT_DB_NAME

          static final String DEFAULT_DB_NAME

      The name of the default database
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### createNonShared

          static MongoClient createNonShared(Vertx vertx,
                                             JsonObject config)

      Create a Mongo client which maintains its own data source.
      Parameters:
        `vertx` - the Vert.x instance
        `config` - the configuration
      Returns:
        the client

    - #### createShared

          static MongoClient createShared(Vertx vertx,
                                          JsonObject config,
                                          String dataSourceName)

      Create a Mongo client which shares its data source with any other Mongo clients created with the same data source name
      Parameters:
        `vertx` - the Vert.x instance
        `config` - the configuration
        `dataSourceName` - the data source name
      Returns:
        the client

    - #### createShared

          static MongoClient createShared(Vertx vertx,
                                          JsonObject config)

      Like `createShared(io.vertx.core.Vertx, JsonObject, String)` but with the default data source name
      Parameters:
        `vertx` - the Vert.x instance
        `config` - the configuration
      Returns:
        the client

    - #### save

          MongoClient save(String collection,
                           JsonObject document,
                           Handler<AsyncResult<String>> resultHandler)

      Save a document in the specified collection

      This operation might change _id field of document parameter

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

    - #### saveWithOptions

          MongoClient saveWithOptions(String collection,
                                      JsonObject document,
                                      WriteOption writeOption,
                                      Handler<AsyncResult<String>> resultHandler)

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

      This operation might change _id field of document parameter

      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

    - #### insert

          MongoClient insert(String collection,
                             JsonObject document,
                             Handler<AsyncResult<String>> resultHandler)

      Insert a document in the specified collection

      This operation might change _id field of document parameter

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

    - #### insertWithOptions

          MongoClient insertWithOptions(String collection,
                                        JsonObject document,
                                        WriteOption writeOption,
                                        Handler<AsyncResult<String>> resultHandler)

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

      This operation might change _id field of document parameter

      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

    - #### update

          @Deprecated
          MongoClient update(String collection,
                                         JsonObject query,
                                         JsonObject update,
                                         Handler<AsyncResult<Void>> resultHandler)

      Deprecated.
      Update matching documents in the specified collection
      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

    - #### updateCollection

          MongoClient updateCollection(String collection,
                                       JsonObject query,
                                       JsonObject update,
                                       Handler<AsyncResult<MongoClientUpdateResult>> resultHandler)

      Update matching documents in the specified collection and return the handler with MongoClientUpdateResult result
      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

    - #### updateWithOptions

          @Deprecated
          MongoClient updateWithOptions(String collection,
                                                    JsonObject query,
                                                    JsonObject update,
                                                    UpdateOptions options,
                                                    Handler<AsyncResult<Void>> resultHandler)

      Deprecated.
      Update matching documents in the specified collection, specifying options
      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
        `resultHandler` - will be called when complete

    - #### updateCollectionWithOptions

          MongoClient updateCollectionWithOptions(String collection,
                                                  JsonObject query,
                                                  JsonObject update,
                                                  UpdateOptions options,
                                                  Handler<AsyncResult<MongoClientUpdateResult>> resultHandler)

      Update matching documents in the specified collection, specifying options and return the handler with MongoClientUpdateResult result
      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
        `resultHandler` - will be called when complete

    - #### replace

          @Deprecated
          MongoClient replace(String collection,
                                          JsonObject query,
                                          JsonObject replace,
                                          Handler<AsyncResult<Void>> resultHandler)

      Deprecated.
      Replace matching documents in the specified collection

      This operation might change _id field of replace parameter

      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

    - #### replaceDocuments

          MongoClient replaceDocuments(String collection,
                                       JsonObject query,
                                       JsonObject replace,
                                       Handler<AsyncResult<MongoClientUpdateResult>> resultHandler)

      Replace matching documents in the specified collection and return the handler with MongoClientUpdateResult result
      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

    - #### replaceWithOptions

          @Deprecated
          MongoClient replaceWithOptions(String collection,
                                                     JsonObject query,
                                                     JsonObject replace,
                                                     UpdateOptions options,
                                                     Handler<AsyncResult<Void>> resultHandler)

      Deprecated.
      Replace matching documents in the specified collection, specifying options

      This operation might change _id field of replace parameter

      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
        `resultHandler` - will be called when complete

    - #### replaceDocumentsWithOptions

          MongoClient replaceDocumentsWithOptions(String collection,
                                                  JsonObject query,
                                                  JsonObject replace,
                                                  UpdateOptions options,
                                                  Handler<AsyncResult<MongoClientUpdateResult>> resultHandler)

      Replace matching documents in the specified collection, specifying options and return the handler with MongoClientUpdateResult result
      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
        `resultHandler` - will be called when complete

    - #### find

          MongoClient find(String collection,
                           JsonObject query,
                           Handler<AsyncResult<List<JsonObject>>> resultHandler)

      Find matching documents in the specified collection
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `resultHandler` - will be provided with list of documents

    - #### findBatch

          MongoClient findBatch(String collection,
                                JsonObject query,
                                Handler<AsyncResult<JsonObject>> resultHandler)

      Find matching documents in the specified collection. This method use batchCursor for returning each found document.
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `resultHandler` - will be provided with each found document

    - #### findWithOptions

          MongoClient findWithOptions(String collection,
                                      JsonObject query,
                                      FindOptions options,
                                      Handler<AsyncResult<List<JsonObject>>> resultHandler)

      Find matching documents in the specified collection, specifying options
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `options` - options to configure the find
        `resultHandler` - will be provided with list of documents

    - #### findBatchWithOptions

          MongoClient findBatchWithOptions(String collection,
                                           JsonObject query,
                                           FindOptions options,
                                           Handler<AsyncResult<JsonObject>> resultHandler)

      Find matching documents in the specified collection, specifying options. This method use batchCursor for returning each found document.
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `options` - options to configure the find
        `resultHandler` - will be provided with each found document

    - #### findOne

          MongoClient findOne(String collection,
                              JsonObject query,
                              JsonObject fields,
                              Handler<AsyncResult<JsonObject>> resultHandler)

      Find a single matching document in the specified collection

      This operation might change _id field of query parameter

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

    - #### count

          MongoClient count(String collection,
                            JsonObject query,
                            Handler<AsyncResult<Long>> resultHandler)

      Count matching documents in a collection.
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `resultHandler` - will be provided with the number of matching documents

    - #### remove

          @Deprecated
          MongoClient remove(String collection,
                                         JsonObject query,
                                         Handler<AsyncResult<Void>> resultHandler)

      Deprecated.
      Remove matching documents from a collection
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `resultHandler` - will be called when complete

    - #### removeDocuments

          MongoClient removeDocuments(String collection,
                                      JsonObject query,
                                      Handler<AsyncResult<MongoClientDeleteResult>> resultHandler)

      Remove matching documents from a collection and return the handler with MongoClientDeleteResult result
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `resultHandler` - will be called when complete

    - #### removeWithOptions

          @Deprecated
          MongoClient removeWithOptions(String collection,
                                                    JsonObject query,
                                                    WriteOption writeOption,
                                                    Handler<AsyncResult<Void>> resultHandler)

      Deprecated.
      Remove matching documents from a collection with the specified write option
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `writeOption` - the write option to use
        `resultHandler` - will be called when complete

    - #### removeDocumentsWithOptions

          MongoClient removeDocumentsWithOptions(String collection,
                                                 JsonObject query,
                                                 WriteOption writeOption,
                                                 Handler<AsyncResult<MongoClientDeleteResult>> resultHandler)

      Remove matching documents from a collection with the specified write option and return the handler with MongoClientDeleteResult result
      Parameters:
        `collection` - the collection
        `query` - query used to match documents
        `writeOption` - the write option to use
        `resultHandler` - will be called when complete

    - #### removeOne

          @Deprecated
          MongoClient removeOne(String collection,
                                            JsonObject query,
                                            Handler<AsyncResult<Void>> resultHandler)

      Deprecated.
      Remove a single matching document from a collection
      Parameters:
        `collection` - the collection
        `query` - query used to match document
        `resultHandler` - will be called when complete

    - #### removeDocument

          MongoClient removeDocument(String collection,
                                     JsonObject query,
                                     Handler<AsyncResult<MongoClientDeleteResult>> resultHandler)

      Remove a single matching document from a collection and return the handler with MongoClientDeleteResult result
      Parameters:
        `collection` - the collection
        `query` - query used to match document
        `resultHandler` - will be called when complete

    - #### removeOneWithOptions

          @Deprecated
          MongoClient removeOneWithOptions(String collection,
                                                       JsonObject query,
                                                       WriteOption writeOption,
                                                       Handler<AsyncResult<Void>> resultHandler)

      Deprecated.
      Remove a single matching document from a collection with the specified write option
      Parameters:
        `collection` - the collection
        `query` - query used to match document
        `writeOption` - the write option to use
        `resultHandler` - will be called when complete

    - #### removeDocumentWithOptions

          MongoClient removeDocumentWithOptions(String collection,
                                                JsonObject query,
                                                WriteOption writeOption,
                                                Handler<AsyncResult<MongoClientDeleteResult>> resultHandler)

      Remove a single matching document from a collection with the specified write option and return the handler with MongoClientDeleteResult result
      Parameters:
        `collection` - the collection
        `query` - query used to match document
        `writeOption` - the write option to use
        `resultHandler` - will be called when complete

    - #### createCollection

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

      Create a new collection
      Parameters:
        `collectionName` - the name of the collection
        `resultHandler` - will be called when complete

    - #### getCollections

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

      Get a list of all collections in the database.
      Parameters:
        `resultHandler` - will be called with a list of collections.

    - #### dropCollection

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

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

    - #### runCommand

          MongoClient runCommand(String commandName,
                                 JsonObject command,
                                 Handler<AsyncResult<JsonObject>> resultHandler)

      Run an arbitrary MongoDB command.
      Parameters:
        `commandName` - the name of the command
        `command` - the command
        `resultHandler` - will be called with the result.

    - #### distinct

          MongoClient distinct(String collection,
                               String fieldName,
                               String resultClassname,
                               Handler<AsyncResult<JsonArray>> resultHandler)

      Gets the distinct values of the specified field name. Return a JsonArray containing distinct values (eg: [ 1 , 89 ])
      Parameters:
        `collection` - the collection
        `fieldName` - the field name
        `resultHandler` - will be provided with array of values.

    - #### distinctBatch

          MongoClient distinctBatch(String collection,
                                    String fieldName,
                                    String resultClassname,
                                    Handler<AsyncResult<JsonObject>> resultHandler)

      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:
        `collection` - the collection
        `fieldName` - the field name
        `resultHandler` - will be provided with each found value

    - #### close

          void close()

      Close the client and release its resources

Copyright © 2016. All rights reserved.