-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update sample http server with db-test
- Loading branch information
1 parent
474e328
commit 9f876f8
Showing
3 changed files
with
22 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
import org.mongodb.scala.Document | ||
import org.mongodb.scala.MongoClient | ||
import org.mongodb.scala.MongoCollection | ||
|
||
import tour.Helpers._ | ||
import org.mongodb.scala.MongoDatabase | ||
|
||
object Database { | ||
|
||
def test(): Unit = | ||
println("Connecting to MongoDB...") | ||
val mongoClient = MongoClient(sys.env("DATABASE_URL")) | ||
val database = mongoClient.getDatabase("mydb") | ||
database.createCollection("test2") | ||
val collection: MongoCollection[Document] = database.getCollection("test2") | ||
|
||
val document = Document( | ||
"name" -> "MongoDB", | ||
"type" -> "database", | ||
"count" -> 1, | ||
"info" -> Document("x" -> 203, "y" -> 102), | ||
) | ||
|
||
collection.insertOne(document).results() | ||
collection.find().printResults() | ||
println("Document inserted") | ||
def connect(db_name: String): MongoDatabase = MongoClient(sys.env("DATABASE_URL")) | ||
.getDatabase(db_name) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters