Connecting to MongoDB with Casbah
The official MongoDB driver for Scala is called Casbah. Rather than a fully-fledged driver, Casbah wraps the Java Mongo driver, providing a more functional interface. There are other MongoDB drivers for Scala, which we will discuss briefly at the end of this chapter. For now, we will stick to Casbah.
Let's start by adding Casbah to our
scalaVersion := "2.11.7" libraryDependencies += "org.mongodb" %% "casbah" % "3.0.0"
Casbah also expects
slf4j bindings (a Scala logging framework) to be available, so let's also add
libraryDependencies += "org.slf4j" % "slf4j-nop" % "1.7.12"
We can now start an SBT console and import Casbah in the Scala shell:
$ sbt console scala> import com.mongodb.casbah.Imports._ ...