Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. private Morphia morphia;
  2. private MongoClient mongoClient;
  3.  
  4. morphia = new Morphia();
  5. // Person is an entity object with Morphia annotations
  6. morphia.map(Person.class);
  7.  
  8. // THESE properties MUST be read from environment variables in Spring BOOT.
  9. final String host = "localhost";
  10. final int port = 27017;
  11.  
  12. mongoClient = new MongoClient(host, port);
  13.  
  14. //Set database
  15. // this instance would be autowired all data access classes
  16. Datastore ds = morphia.createDatastore(mongoClient, "dataStoreInstanceId");
  17.  
  18. // this is how instance would be used in those data accesses classes
  19. Person p = ds.find(Person.class, "username", "john").get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement