0

I'm working on play 2.3 with reactive mongo play plugin. I want to query the db which should give me all the entries.

Below I have given a snippet. The next line to the comment "FIND ALL THE TAGS", is the place where I am trying to fetch all the tags. I am looking for something like findAll equivalent method like in Spring Data JPA.

def tagCollection: JSONCollection = db.collection[JSONCollection]("tags")

def findTags = Action.async {
  // **FIND ALL THE TAGS**
  val cursor: Cursor[Tag] = tagCollection.find(Json.obj("name" -> )).cursor[Tag]

  val futureTagsList: Future[List[Tag]] = cursor.collect[List]()

  val futureTagsJsonArray: Future[JsArray] = futureTagsList.map {
    tags => Json.arr(tags)
  }
  futureTagsJsonArray.map {
    tags => Ok(tags(0))
  }

Also is there any library documentation available?

s4nk
  • 647
  • 1
  • 9
  • 18
Kaushik
  • 1,271
  • 2
  • 18
  • 35

1 Answers1

1

In order to fetch all tags you just have to pass an empty query:

val cursor: Cursor[Tag] = tagCollection.find(Json.obj()).cursor[Tag]
s4nk
  • 647
  • 1
  • 9
  • 18
  • For Json.obj: No Json serializer as JsObject found for type play.api.libs.json.JsObject. Try to implement an implicit OWrites or OFormat for this type. – pcejrowski Feb 21 '17 at 13:23