Build mongo db client.

@param mongo the mongo
@return the mongo client
546398
public static MongoClient buildMongoDbClient(final BaseMongoDbProperties mongo) {

        if (StringUtils.isNotBlank(mongo.getClientUri())) {
            LOGGER.debug("Using MongoDb client URI [{}] to connect to MongoDb instance", mongo.getClientUri());
            return buildMongoDbClient(mongo.getClientUri(), buildMongoDbClientOptions(mongo));
        }

        val serverAddresses = mongo.getHost().split(",");
        if (serverAddresses.length == 0) {
            throw new BeanCreationException("Unable to build a MongoDb client without any hosts/servers defined");
        }

        List<ServerAddress> servers = new ArrayList<>();
        if (serverAddresses.length > 1) {
            LOGGER.debug("Multiple MongoDb server addresses are defined. Ignoring port [{}], "
                + "assuming ports are defined as part of the address", mongo.getPort());
            servers = Arrays.stream(serverAddresses)
                .filter(StringUtils::isNotBlank)
                .map(ServerAddress::new)
                .collect(Collectors.toList());
        } else {
            val port = mongo.getPort() > 0 ? mongo.getPort() : DEFAULT_PORT;
            LOGGER.debug("Found single MongoDb server address [{}] using port [{}]", mongo.getHost(), port);
            val addr = new ServerAddress(mongo.getHost(), port);
            servers.add(addr);
        }

        val credential = buildMongoCredential(mongo);
        return new MongoClient(servers, CollectionUtils.wrap(credential), buildMongoDbClientOptions(mongo));
    }
12112
public function switchDb($db_name)
    {
        $self = $this;

        return $this->app['mongo'] = $this->app->share(
            function () use ($db_name, $self) {
                return new Db($db_name, $self->client, $self->app);
            }
        );
    }
1166996
function connect(uri, callback) {
  console.log('connecting to database (' + uri + ')');
  mongo.MongoClient.connect(uri, {safe: true}, function (err, client) {
    if (err) return callback(err);

    db = client;
    db.addListener("error", function (error) {
      console.log("mongo client error: " + error);
    });

    callback(null, db);
  });
}
656864
function Client() {
	this._host = '127.0.0.1'; // localhost
	this._port = 4242; // default OpenTSDB port

	// Output: (opinionated defaults)
	this._ms = true;
	this._arrays = true;
	this._tsuids = false;
	this._annotations = 'none'; // ["none","local","all"]

	// Time:
	this._start = null; // required
	this._end = null;

	// Queries:
	this._queries = null; // required

	// URL generator:
	this._url = urlFactory( this );

	return this;
}
1212107
def connect(self):
        
        self.client = MongoClient(self.mongo_uri)
        self.db = self.client[self.db_name]
785647
public static MongoDatabase createDatabaseProxy(final MongoDatabase database) {
		if (DISABLED) {
			return database;
		}
		SERVICES_COUNTER.setDisplayed(!COUNTER_HIDDEN);
		SERVICES_COUNTER.setUsed(true);
		return JdbcWrapper.createProxy(database, new MongoDatabaseHandler(database));
	}
455037
@Override
    protected Client instantiateClient(String persistenceUnit)
    {
        return new MongoDBClient(mongoDB, indexManager, reader, persistenceUnit, externalProperties, clientMetadata,
                kunderaMetadata);
    }
1137128
private function getMongoClient() {
        if ($this->mongoClient === null) {
            try {
                $this->mongoClient = new MongoClient($this->params['server'], $this->params['options']);
            } catch (MongoException $e) {
                throw new DatabaseException('Could not connect to database', 500, $e);
            }
        }

        return $this->mongoClient;
    }
1154572
@SuppressWarnings("deprecation")
    public Datastore createDatastore(final MongoClient mongoClient, final String dbName) {
        return new DatastoreImpl(this, mongoClient, dbName);
    }
994167
public function getMongoClient()
    {
        if ($this->mongoClient) {
            return $this->mongoClient;
        }

        $this->mongoClient = new \MongoClient(
            $this->dsn,
            $this->connectOptions
        );
        
        return $this->mongoClient;
    }
222869
@When("^I execute a query '(.+?)' of type '(json|string)' in mongo '(.+?)' database using collection '(.+?)' with:$")
    public void sendQueryOfType(String query, String type, String database, String collection, DataTable modifications) throws Exception {
        try {
            commonspec.setResultsType("mongo");
            String retrievedData = commonspec.retrieveData(query, type);
            String modifiedData = commonspec.modifyData(retrievedData, type, modifications);
            commonspec.getMongoDBClient().connectToMongoDBDataBase(database);
            DBCollection dbCollection = commonspec.getMongoDBClient().getMongoDBCollection(collection);
            DBObject dbObject = (DBObject) JSON.parse(modifiedData);
            DBCursor cursor = dbCollection.find(dbObject);
            commonspec.setMongoResults(cursor);
        } catch (Exception e) {
            commonspec.getExceptions().add(e);
        }
    }
465129
public EmbeddedMongoDB start() {
        if (!this.active) {
            try {
                this.mongodProcess = MongodStarter.getDefaultInstance().prepare(new MongodConfigBuilder()
                .version(this.version)
                .net(new Net(this.host, this.port, false))
                .build()).start();

                this.active = true;
                LOG.info("Successfully started EmbeddedMongoDB @ {}:{}", this.host, this.port);
            } catch (final IOException e) {
                LOG.error("Failed to start EmbeddedMongoDB @ {}:{}", this.host, this.port, e);
            }
        }
        
        return this;
    }
233471
@Override
    protected Client instantiateClient(String persistenceUnit)
    {
        return new HBaseClient(indexManager, conf, connection, reader, persistenceUnit, externalProperties,
                clientMetadata, kunderaMetadata);
    }
354205
def get_collection(self, **kwargs):
        
        from pymongo import MongoClient

        if self.host and self.port:
            client = MongoClient(host=config.host, port=config.port)
        else:
            client = MongoClient()
        db = client[self.dbname]

        # Authenticate if needed
        if self.user and self.password:
            db.autenticate(self.user, password=self.password)

        return db[self.collection]
287985
function connect(dbUri, debugFlag, mongos) {
    var deferred = Q.defer();
    var opts = {
        server: { socketOptions: { keepAlive: 1, connectTimeoutMS: 30000 } },
        replset: { socketOptions: { keepAlive: 1, connectTimeoutMS : 30000 } }
    };

    if (mongos) {
        opts.mongos = true;
    }

    mongoose.set('debug', debugFlag);

    // make sure we disconnect any other existing connections
    mongoose.disconnect(function () {
        mongoose.connect(dbUri, opts, function (err)  {
            err ? deferred.reject(err) : deferred.resolve();
        });
    });

    return deferred.promise;
}
221216
public function connect()
    {
        if (!isset($this->configuration['host']) || !isset($this->configuration['database'])) {
            throw new NoSQLDriverException('Can not connect to MongoDB because configuration for this driver was not provided.');
        }

        try {
            $this->connection = new \MongoDB\Client(
                $this->configuration['host'],
                $this->configuration['options'],
                $this->configuration['driver_options']
            );
        } catch (\Exception $e) {
            throw new NoSQLDriverException('Can not connect to storage because of: '.$e->getMessage(), $e->getCode(), $e);
        }

        $this->db = $this->connection->selectDatabase($this->configuration['database']);

        return $this->connection;
    }
1135307
function start(callback) {
    var dbDeferred = Q.defer();
    config = defaultConfig;

    if (typeof gmeConfig.rest.components[CONFIG_ID] === 'object' &&
        gmeConfig.rest.components[CONFIG_ID].options) {

        config = gmeConfig.rest.components[CONFIG_ID].options;
    }

    mongodb.MongoClient.connect(config.mongo.uri, config.mongo.options, function (err, db) {
        if (err) {
            dbDeferred.reject(err);
        } else {
            dbConn = db;
            dbDeferred.resolve();
        }
    });

    return dbDeferred.promise.nodeify(callback);
}