From 84b4d78cd0be54e5b0769c41f61a707e8cbe7122 Mon Sep 17 00:00:00 2001 From: Richard Smedley Date: Wed, 27 Aug 2025 10:10:47 +0100 Subject: [PATCH] SubDocument from replicas --- .../devguide/examples/scala/SubDocument.scala | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/modules/devguide/examples/scala/SubDocument.scala b/modules/devguide/examples/scala/SubDocument.scala index 021dd59..a69716b 100644 --- a/modules/devguide/examples/scala/SubDocument.scala +++ b/modules/devguide/examples/scala/SubDocument.scala @@ -341,4 +341,33 @@ val result = collection.get("player432") // #end::sync-durability[] } -} \ No newline at end of file + def lookupInAnyReplica(collection: Collection): Unit = { + // tag::lookup-in-any-replica[] + val result: Try[LookupInReplicaResult] = + collection.lookupInAnyReplica("hotel_1368", Seq(LookupInSpec.get("geo.lat"))) + + result match { + case Success(value) => + val str = value.contentAs[String](0) + println(s"Latitude = ${str}") + case Failure(exception) => println(s"Error: ${exception}") + } + // end::lookup-in-any-replica[] + } + + def lookupInAllReplicas(collection: Collection): Unit = { + // tag::lookup-in-all-replicas[] + val results: Try[Iterable[LookupInReplicaResult]] = + collection.lookupInAllReplicas("hotel_1368", Seq(LookupInSpec.get("geo.lat"))) + + results match { + case Success(replicas) => + replicas.foreach(replica => { + val str = replica.contentAs[String](0) + println(s"Latitude = ${str}") + }) + case Failure(exception) => println(s"Error: ${exception}") + } + // end::lookup-in-all-replicas[] + } +}