Last active
December 14, 2015 06:49
-
-
Save Narigo/5046275 to your computer and use it in GitHub Desktop.
Cannot query nested documents (Line #39)
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
package reactivemongotest | |
import scala.concurrent.Await | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.Future | |
import scala.concurrent.duration.DurationInt | |
import org.junit.Test | |
import reactivemongo.api.MongoConnection | |
import reactivemongo.bson.BSONDocument | |
import reactivemongo.bson.BSONInteger | |
import reactivemongo.bson.BSONString | |
import reactivemongo.bson.handlers.DefaultBSONHandlers.DefaultBSONDocumentReader | |
import reactivemongo.bson.handlers.DefaultBSONHandlers.DefaultBSONDocumentWriter | |
import reactivemongo.bson.handlers.DefaultBSONHandlers.DefaultBSONReaderHandler | |
import scala.util.Failure | |
import scala.util.Success | |
import reactivemongo.core.commands.LastError | |
import reactivemongo.bson.BSONElement | |
class ReactiveMongoTest { | |
@Test | |
def someTest() { | |
import scala.concurrent.ExecutionContext.Implicits.global | |
val connection = MongoConnection(List("localhost:27017")) | |
val db = connection("test") | |
val collection = db("vertx-test") | |
val document = BSONDocument( | |
"nickname" -> BSONString("Tester"), | |
"data" -> BSONDocument( | |
"age" -> BSONInteger(15), | |
"address" -> BSONString("Fakestreet 123"))) | |
val somePointInFuture = (collection.insert(document) flatMap { | |
lastError => | |
println("lastError: " + lastError) | |
// The query does not work for nested data | |
val query = document //BSONDocument("data.age" -> BSONInteger(15)) | |
val filter = BSONDocument("nickname" -> BSONInteger(1)) | |
println("This shows up!") | |
val cursor = collection.find(query, filter) | |
println("This shows up now, too!") | |
cursor.toList | |
} andThen { | |
case Success(cursorList) => | |
println("another success! = " + cursorList) | |
for (result <- cursorList) yield result | |
case Failure(f) => | |
println("uh oh, error: " + f) | |
}) | |
val res = Await.result(somePointInFuture, 15 seconds) | |
for (doc <- res) { | |
println(doc.get("nickname")) | |
} | |
println("done") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment