Skip to content

Basic Setup

Connect to a local MongoDB and configure Morphium.

MorphiumConfig cfg = new MorphiumConfig();
cfg.connectionSettings().setDatabase("myapp");
cfg.clusterSettings().addHostToSeed("localhost", 27017);

Morphium morphium = new Morphium(cfg);

Replica set example

cfg.clusterSettings().addHostToSeed("mongo1", 27017);
cfg.clusterSettings().addHostToSeed("mongo2", 27017);
cfg.clusterSettings().addHostToSeed("mongo3", 27017);

Authentication

cfg.authSettings().setMongoLogin("user");
cfg.authSettings().setMongoPassword("secret");

Driver selection (optional)

cfg.driverSettings().setDriverName("PooledDriver"); // default