Reputation: 356
My query using ReactiveMongo:
collection
.find(
Json.obj("relateds" -> Json.obj("$elemMatch" -> activityRelated)),
Json.obj("subscriberId" -> 1, "_id" -> 0)
)
.cursor[BSONObjectID]
.collect[Seq]()
This is meant to return only one field "subscriberId" for each found document. The final output type should be Future[Seq[BSONObjectID]]
But it fails with:
Failure(java.lang.RuntimeException: JsError(List((,List(ValidationError(unhandled json value,WrappedArray()))))))
Any Ideas how to do this ?
Thanks in advance
Upvotes: 2
Views: 958
Reputation: 365
Response for this query is sequence of objects, not values:
{ subscriberId : "foo" }
So, you need to define case class with single field for this id and then set cursor type as this case class or try something like that:
collection
.find(
Json.obj("relateds" -> Json.obj("$elemMatch" -> activityRelated)),
Json.obj("subscriberId" -> 1, "_id" -> 0)
)
.cursor[JsValue]
.collect[Seq]()
.map(_.map(_.\("subscriberId").as[BSONObjectID]))
Upvotes: 2