Guest User

Untitled

a guest
Mar 27th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. C:Program FilesMongoDBServer3.6binmongo.exe" database.foocorp.com:27017/mydatabase -u salimfadhley -p secretpassowrd
  2. MongoDB shell version v3.6.3
  3. connecting to: mongodb://database.foocorp.com:27017/mydatabase
  4. MongoDB server version: 3.4.4
  5. WARNING: shell and server versions do not match
  6. > db.mycollection.find()
  7. ... got loads of data back ...
  8.  
  9. import org.mongodb.scala.{Document, MongoClient, MongoCollection}
  10.  
  11.  
  12. object ConnectionDemo extends App {
  13.  
  14. val dbHost = "database.foocorp.com"
  15. val dbPort = 27017
  16. val dbUserName = "salimfadhley"
  17. val dbPassword = "secretpassword"
  18. val dbName = "dashboard"
  19. val collectionName = "mycollection"
  20. val mongoClient = MongoClient(s"mongodb://$dbUserName:$dbPassword@$dbHost:$dbPort/?authsource=$dbName")
  21.  
  22. val mongoDatabase = mongoClient.getDatabase(dbName)
  23. val result = mongoDatabase.getCollection(collectionName).find()
  24.  
  25. result.subscribe(
  26. (d:Document) => println(d.toJson()),
  27. (e:Throwable) => println(s"An error occurred, ${e.getMessage}"),
  28. () => println("Done")
  29.  
  30. )
Add Comment
Please, Sign In to add comment