import reactivemongo.api.{BSONSerializationPack, MongoDriver}
import reactivemongo.api.commands.Command
import reactivemongo.bson.{BSONArray, BSONDocument}
import scala.concurrent.ExecutionContext.Implicits.global
object TestMongo extends App {
val driver = new MongoDriver
val servers = List("localhost:27017")
val connection = driver.connection(servers)
val db = connection.db("test")
val command = BSONDocument(
"aggregate" -> "test",
"pipeline" -> BSONArray(
BSONDocument("$match" -> BSONDocument("foo" -> "bar"))
)
)
val runner = Command.run(BSONSerializationPack)
runner.apply(db, runner.rawCommand(command)).one[BSONDocument].map(b => println(BSONDocument.pretty(b))).recover {
case e: Exception => println(e.printStackTrace())
}
}
name := "Test"
version := "1.0"
scalaVersion := "2.11.7"
resolvers ++= Seq(
"Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
)
libraryDependencies ++= Seq(
"org.reactivemongo" %% "reactivemongo" % "0.11.7"
)
[info] Running TestMongo ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.{ result: [ 0: { _id: BSONObjectID("55f01130ad94330a95bfc128"), foo: "bar" } ], ok: BSONDouble(1.0)}
val db = connection.db("test")
You'd better use the ReactiveMongo aggregate framework (rather than RAW command): http://reactivemongo.org/releases/0.11/documentation/advanced-topics/aggregation.html .
--
You received this message because you are subscribed to a topic in the Google Groups "ReactiveMongo - http://reactivemongo.org" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/reactivemongo/8ygxmoaSmQY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to reactivemong...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import scala.concurrent.ExecutionContext.Implicits.global
import reactivemongo.api._
object Main extends App {
lazy val md = MongoDriver()
try {
val con = md.connection(Seq("localhost:27017"))
con.db("test")
} finally {
md.close()
}
}