Created
June 19, 2015 13:56
-
-
Save duketon/bf4d484852722883228e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val client = MongoClients.create(new ConnectionString("localhost:27017")) | |
val db = client.getDatabase("myDb") | |
val collection = db.getCollection("myCollection") | |
def findAndModify(filter: Document, update: Document, options: FindOneAndUpdateOptions): Future[Document] = { | |
val p: Promise[Document] = Promise() | |
collection.findOneAndUpdate( | |
filter, update, options, | |
new SingleResultCallback[Document] { | |
override def onResult(result: Document, t: Throwable): Unit = | |
if (t == null) p.success(result) else p.failure(t) | |
}) | |
p.future | |
} | |
val queryOptions = | |
new FindOneAndUpdateOptions() | |
.upsert(true) | |
.returnDocument(ReturnDocument.AFTER) | |
.upsert(false) | |
findAndModify(new Document("lastName", "Smith"), new Document("lastName", "Jones"), queryOptions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment