I call the findAndUpdate function on a mongo collection to increase a counter, and I want to get the value of the counter for further use.Here is my code:
collection.findAndUpdate(
BSONDocument("name" -> "counter"),
BSONDocument("$inc" -> BSONDocument("count" -> 1)),
fetchNewObject = true,
upsert = true
).map{ e =>
println("count = " + e.value.getAs[Int]("count"))
//I want to do something with the count here
}
This doesn't compile because e.value.getAs[Int]("count")
seems to be wrong.
The compile error is:
value getAs is not a member of Option[service.this.collection.BatchCommands.FindAndModifyCommand.pack.Document]
Please kindly advise, thanks!
Try this: