Kaushik
Kaushik

Reputation: 1349

Find all the entries in collection - Play 2.3 reactive-mongo plugin

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?

Upvotes: 0

Views: 2610

Answers (1)

s4nk
s4nk

Reputation: 685

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

val cursor: Cursor[Tag] = tagCollection.find(Json.obj()).cursor[Tag]

Upvotes: 1

Related Questions