Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Morphia morphia;
- private MongoClient mongoClient;
- morphia = new Morphia();
- // Person is an entity object with Morphia annotations
- morphia.map(Person.class);
- // THESE properties MUST be read from environment variables in Spring BOOT.
- final String host = "localhost";
- final int port = 27017;
- mongoClient = new MongoClient(host, port);
- //Set database
- // this instance would be autowired all data access classes
- Datastore ds = morphia.createDatastore(mongoClient, "dataStoreInstanceId");
- // this is how instance would be used in those data accesses classes
- Person p = ds.find(Person.class, "username", "john").get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement