package io.clearnote.infrastructure.mongo

import com.mongodb.client.model.UpdateOptions
import com.mongodb.client.result.UpdateResult
import com.mongodb.rx.client.MongoCollection
import org.bson.Document
import org.bson.conversions.Bson
import rx.Observable

fun MongoCollection<Document>.upsert(find: Bson, update: Bson): Observable<UpdateResult> {
    return this.updateOne(find, Document("\$set", update), UpdateOptions().upsert(true))
}
