Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C:Program FilesMongoDBServer3.6binmongo.exe" database.foocorp.com:27017/mydatabase -u salimfadhley -p secretpassowrd
- MongoDB shell version v3.6.3
- connecting to: mongodb://database.foocorp.com:27017/mydatabase
- MongoDB server version: 3.4.4
- WARNING: shell and server versions do not match
- > db.mycollection.find()
- ... got loads of data back ...
- import org.mongodb.scala.{Document, MongoClient, MongoCollection}
- object ConnectionDemo extends App {
- val dbHost = "database.foocorp.com"
- val dbPort = 27017
- val dbUserName = "salimfadhley"
- val dbPassword = "secretpassword"
- val dbName = "dashboard"
- val collectionName = "mycollection"
- val mongoClient = MongoClient(s"mongodb://$dbUserName:$dbPassword@$dbHost:$dbPort/?authsource=$dbName")
- val mongoDatabase = mongoClient.getDatabase(dbName)
- val result = mongoDatabase.getCollection(collectionName).find()
- result.subscribe(
- (d:Document) => println(d.toJson()),
- (e:Throwable) => println(s"An error occurred, ${e.getMessage}"),
- () => println("Done")
- )
Add Comment
Please, Sign In to add comment