# How to run aggregation?

Build the aggregate pipeline as a list of Document objects and pass it to aggregate api on the respective collection as shown below:






 

import scala.collection.JavaConverters._
val list: List[Document] = List(
      new Document("$match", LotteryQuery().lotteryName.startsWith("metastay").toDocument),
      new Document("$project", new Document("lotteryName", "1"))
    )
val resultSet = LotteryReader().collection.aggregate(list.asJava)