# Need to insert only when the row doesnt exist?
Use upsert when you want to update an exist row, if not insert a new row.
Steps:
- Specify the query condition using the collection's Query class, ex:
LotteryQuery - Compose the update using the collection's Update class, ex:
LotteryUpdate - Use the collection's Writer api
upsertpassing the query & update.
val lotteryQry = LotteryQuery().lotteryName.is("lotto-1")
val lotteryUpd = LotteryUpdate().open.set(false)
LotteryWriter().upsert(lotteryQry, lotteryUpd)
Note: If "lotto-1" doesnt exist, upsert will insert a row with lotteryName "lotto-1" & open set to "false"
REFERENCE