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.
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)