0

I have been spending time 3 hours and I wasn't success trying to retrieve a BSONDocument with all of the attributes. I don't why I only get the first attribute... where are the others?

I wrote the following test

describe("Testing reactive map user") {
    it(" convert an user to BSONDocument") {

        val basicProfile = BasicProfile("1", "1", Option("pesk"), Option("pesk"),
            Option("pesk pesk"), Option("pesk@gmail.com"), Option("url"),
            AuthenticationMethod.UserPassword, Option(new OAuth1Info("token", "secret")),
            Option(new OAuth2Info("token", Option("secret"))),
            Option(new PasswordInfo("hasher", "password", Option("salt"))))

        val user = User(Option(BSONObjectID.generate), basicProfile, List(), "31.55, 53.66", List[User](), Option(DateTime.now))

        val result = User.UserBSONWriter.write(user)

        assert(result.getAs[String]("providerId") == "1")
    }
}

The UserBSONWriter

implicit object UserBSONWriter extends BSONDocumentWriter[User] {
    def write(user: User): BSONDocument = {
        val doc = BSONDocument(
            "_id" -> user.id.getOrElse(BSONObjectID.generate),
            "providerId" -> BSONString(user.basicProfile.providerId),
            "userId" -> BSONString(user.basicProfile.userId))
        println(doc)
        doc
    }
}

And I attach the screenshot of the console. I'm trying to get the value providerId, which is next to BSONObjectID, but I can just only get the first attribute.

Stream(Success((_id,BSONObjectID("54f862fe010000010001a3fb"))), ?)

I will appreciate a lot if somebody can help me. And I have other comment, Im getting some headaches because of the implicitly system which is used by scala's BSON API. It is not trivial to find some docs about these all implicit conversions.

Outupt of println(doc)

BSONDocument(non-empty)

Jørgen R
  • 10,568
  • 7
  • 42
  • 59
Ignacio Giagante
  • 364
  • 1
  • 5
  • 19
  • Can you attach the STDOUT of the console, i.e. `println(doc)` output? – yǝsʞǝla Mar 05 '15 at 06:13
  • In your test you're only trying to fetch one field. Does this test pass? did you try to fetch other fields? – Dimitri Mar 05 '15 at 11:19
  • People, I didnt know what's going on. I run the test again and check all the fields, and its working correctly. By the way, can anybody explain how to use implicit object to convert BSONs all the moment in the app? – Ignacio Giagante Mar 05 '15 at 19:45

0 Answers0