Just started playing with reactivemongo in a simple API I am writing.
case class Foo(
id: Option[BSONObjectID],
bar: String)
object Foo(
// implement implict's which extend BSONReader and BSONWriter as in tutorial docs...
)
Now in my controller,
if I do something simple like:
/...
val query = BSONDocument("bar" -> BSONString("coffee"))
collection.find(query).toList.map { results =>
Ok(results.foldLeft(JsArray(List()))( (obj, res) => obj ++ Json.arr(res) ))
The result is as expected, a JSON array containing all the objects found that matched the query. However I have a couple questions,
First, the result has the JSON in a format which is not desirable, the "_id" field is not just the string representation but rather an object itself:
{
bar: "coffee"
}
I would rather rename the _id field and only display the string like:
{
coffeeId: "50a2c992eca75db398b70439"
bar: "coffee"
}
How can I effect how the BSON is mapped to JSON? What if I didn't even want the objectId field (or any other field for the matter) to be displayed?
I am pretty new to this, and VERY new to mongo / scala 2.10 / play 2.1 I apologize if this is a trivial question or misplaced in this group.
-- Steve