Class ReactiveCollection
- java.lang.Object
-
- com.couchbase.client.java.ReactiveCollection
-
public class ReactiveCollection extends Object
TheReactiveCollectionprovides sophisticated asynchronous access to all collection APIs.This API provides more sophisticated async controls over the
AsyncCollection, but it also comes with a little more overhead. For most use cases we recommend using this API over the other one, unless you really need that last drop of performance and can live with the significantly reduced functionality (in terms of the richness of operators). For example, thisReactiveCollectionis built on top of theAsyncCollection.- Since:
- 3.0.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsyncCollectionasync()Provides access to the underlyingAsyncCollection.ReactiveBinaryCollectionbinary()Provides access to the binary APIs, not used for JSON documents.StringbucketName()Returns the name of the bucket associated with this collection.Corecore()Provides access to the underlyingCore.ClusterEnvironmentenvironment()Provides access to the underlyingClusterEnvironment.Mono<ExistsResult>exists(String id)Checks if the given document ID exists on the active partition with default options.Mono<ExistsResult>exists(String id, ExistsOptions options)Checks if the given document ID exists on the active partition with custom options.Mono<GetResult>get(String id)Fetches a Document from a collection with default options.Mono<GetResult>get(String id, GetOptions options)Fetches a Document from a collection with custom options.Flux<GetReplicaResult>getAllReplicas(String id)Reads all available replicas, including the active, and returns the results as a flux.Flux<GetReplicaResult>getAllReplicas(String id, GetAllReplicasOptions options)Reads all available replicas, including the active, and returns the results as a flux.Mono<GetResult>getAndLock(String id, Duration lockTime)Fetches a full document and write-locks it for the given duration with default options.Mono<GetResult>getAndLock(String id, Duration lockTime, GetAndLockOptions options)Fetches a full document and write-locks it for the given duration with custom options.Mono<GetResult>getAndTouch(String id, Duration expiry)Fetches a full document and resets its expiration time to the value provided with default options.Mono<GetResult>getAndTouch(String id, Duration expiry, GetAndTouchOptions options)Fetches a full document and resets its expiration time to the value provided with custom options.Mono<GetReplicaResult>getAnyReplica(String id)Reads all available replicas, and returns the first found.Mono<GetReplicaResult>getAnyReplica(String id, GetAnyReplicaOptions options)Reads all available replicas, and returns the first found.Mono<MutationResult>insert(String id, Object content)Inserts a full document which does not exist yet with default options.Mono<MutationResult>insert(String id, Object content, InsertOptions options)Inserts a full document which does not exist yet with custom options.Mono<LookupInResult>lookupIn(String id, List<LookupInSpec> specs)Performs lookups to document fragments with default options.Mono<LookupInResult>lookupIn(String id, List<LookupInSpec> specs, LookupInOptions options)Performs lookups to document fragments with custom options.Mono<MutateInResult>mutateIn(String id, List<MutateInSpec> specs)Performs mutations to document fragments with default options.Mono<MutateInResult>mutateIn(String id, List<MutateInSpec> specs, MutateInOptions options)Performs mutations to document fragments with custom options.Stringname()Returns the name of this collection.ReactiveCollectionQueryIndexManagerqueryIndexes()Provides access to query index management at the ReactiveCollection level.Mono<MutationResult>remove(String id)Removes a Document from a collection with default options.Mono<MutationResult>remove(String id, RemoveOptions options)Removes a Document from a collection with custom options.Mono<MutationResult>replace(String id, Object content)Replaces a full document which already exists with default options.Mono<MutationResult>replace(String id, Object content, ReplaceOptions options)Replaces a full document which already exists with custom options.Flux<ScanResult>scan(ScanType scanType)Returns a stream ofScanResultsperforming a Key-Value range scan with default options.Flux<ScanResult>scan(ScanType scanType, ScanOptions options)Returns a stream ofScanResultsperforming a Key-Value range scan with custom options.StringscopeName()Returns the name of the scope associated with this collection.Mono<MutationResult>touch(String id, Duration expiry)Updates the expiry of the document with the given id with default options.Mono<MutationResult>touch(String id, Duration expiry, TouchOptions options)Updates the expiry of the document with the given id with custom options.Mono<Void>unlock(String id, long cas)Unlocks a document if it has been locked previously, with default options.Mono<Void>unlock(String id, long cas, UnlockOptions options)Unlocks a document if it has been locked previously, with custom options.Mono<MutationResult>upsert(String id, Object content)Upserts a full document which might or might not exist yet with default options.Mono<MutationResult>upsert(String id, Object content, UpsertOptions options)Upserts a full document which might or might not exist yet with custom options.
-
-
-
Method Detail
-
async
public AsyncCollection async()
Provides access to the underlyingAsyncCollection.- Returns:
- returns the underlying
AsyncCollection.
-
name
public String name()
Returns the name of this collection.
-
bucketName
public String bucketName()
Returns the name of the bucket associated with this collection.
-
scopeName
public String scopeName()
Returns the name of the scope associated with this collection.
-
environment
public ClusterEnvironment environment()
Provides access to the underlyingClusterEnvironment.
-
binary
public ReactiveBinaryCollection binary()
Provides access to the binary APIs, not used for JSON documents.- Returns:
- the
ReactiveBinaryCollection.
-
queryIndexes
@Volatile public ReactiveCollectionQueryIndexManager queryIndexes()
Provides access to query index management at the ReactiveCollection level.
-
get
public Mono<GetResult> get(String id)
Fetches a Document from a collection with default options.- Parameters:
id- the document id which is used to uniquely identify it.- Returns:
- a
Monoindicating once loaded or failed.
-
get
public Mono<GetResult> get(String id, GetOptions options)
Fetches a Document from a collection with custom options.- Parameters:
id- the document id which is used to uniquely identify it.options- custom options to change the default behavior.- Returns:
- a
Monoindicating once loaded or failed
-
getAndLock
public Mono<GetResult> getAndLock(String id, Duration lockTime)
Fetches a full document and write-locks it for the given duration with default options.Note that the client does not enforce an upper limit on the
DurationlockTime. The maximum lock time by default on the server is 30 seconds. Any value larger than 30 seconds will be capped down by the server to the default lock time, which is 15 seconds unless modified on the server side.- Parameters:
id- the document id which is used to uniquely identify it.lockTime- how long to write-lock the document for (any duration > 30s will be capped to server default of 15s).- Returns:
- a
Monocompleting once loaded or failed.
-
getAndLock
public Mono<GetResult> getAndLock(String id, Duration lockTime, GetAndLockOptions options)
Fetches a full document and write-locks it for the given duration with custom options.Note that the client does not enforce an upper limit on the
DurationlockTime. The maximum lock time by default on the server is 30 seconds. Any value larger than 30 seconds will be capped down by the server to the default lock time, which is 15 seconds unless modified on the server side.- Parameters:
id- the document id which is used to uniquely identify it.lockTime- how long to write-lock the document for (any duration > 30s will be capped to server default of 15s).options- custom options to change the default behavior.- Returns:
- a
Monocompleting once loaded or failed.
-
getAndTouch
public Mono<GetResult> getAndTouch(String id, Duration expiry)
Fetches a full document and resets its expiration time to the value provided with default options.- Parameters:
id- the document id which is used to uniquely identify it.expiry- the new expiration time for the document.- Returns:
- a
Monocompleting once loaded or failed.
-
getAndTouch
public Mono<GetResult> getAndTouch(String id, Duration expiry, GetAndTouchOptions options)
Fetches a full document and resets its expiration time to the value provided with custom options.- Parameters:
id- the document id which is used to uniquely identify it.expiry- the new expiration time for the document.options- custom options to change the default behavior.- Returns:
- a
Monocompleting once loaded or failed.
-
getAllReplicas
public Flux<GetReplicaResult> getAllReplicas(String id)
Reads all available replicas, including the active, and returns the results as a flux.Note that individual errors are ignored, so you can think of this API as a best effort approach which explicitly emphasises availability over consistency.
If the read requests all fail, the flux emits nothing.
- Parameters:
id- the document id.- Returns:
- a flux of results from all replicas
-
getAllReplicas
public Flux<GetReplicaResult> getAllReplicas(String id, GetAllReplicasOptions options)
Reads all available replicas, including the active, and returns the results as a flux.Note that individual errors are ignored, so you can think of this API as a best effort approach which explicitly emphasises availability over consistency.
If the read requests all fail, the flux emits nothing.
- Parameters:
id- the document id.options- the custom options.- Returns:
- a flux of results from all replicas
-
getAnyReplica
public Mono<GetReplicaResult> getAnyReplica(String id)
Reads all available replicas, and returns the first found.If the read requests all fail, the mono emits nothing.
- Parameters:
id- the document id.- Returns:
- a mono containing the first available replica.
-
getAnyReplica
public Mono<GetReplicaResult> getAnyReplica(String id, GetAnyReplicaOptions options)
Reads all available replicas, and returns the first found.If the read requests all fail, the mono emits nothing.
- Parameters:
id- the document id.options- the custom options.- Returns:
- a mono containing the first available replica.
-
exists
public Mono<ExistsResult> exists(String id)
Checks if the given document ID exists on the active partition with default options.- Parameters:
id- the document ID- Returns:
- a
Monocompleting once loaded or failed.
-
exists
public Mono<ExistsResult> exists(String id, ExistsOptions options)
Checks if the given document ID exists on the active partition with custom options.- Parameters:
id- the document IDoptions- to modify the default behavior- Returns:
- a
Monocompleting once loaded or failed.
-
remove
public Mono<MutationResult> remove(String id)
Removes a Document from a collection with default options.- Parameters:
id- the id of the document to remove.- Returns:
- a
Monocompleting once removed or failed.
-
remove
public Mono<MutationResult> remove(String id, RemoveOptions options)
Removes a Document from a collection with custom options.- Parameters:
id- the id of the document to remove.options- custom options to change the default behavior.- Returns:
- a
Monocompleting once removed or failed.
-
insert
public Mono<MutationResult> insert(String id, Object content)
Inserts a full document which does not exist yet with default options.- Parameters:
id- the document id to insert.content- the document content to insert.- Returns:
- a
Monocompleting once inserted or failed.
-
insert
public Mono<MutationResult> insert(String id, Object content, InsertOptions options)
Inserts a full document which does not exist yet with custom options.- Parameters:
id- the document id to insert.content- the document content to insert.options- custom options to customize the insert behavior.- Returns:
- a
Monocompleting once inserted or failed.
-
upsert
public Mono<MutationResult> upsert(String id, Object content)
Upserts a full document which might or might not exist yet with default options.- Parameters:
id- the document id to upsert.content- the document content to upsert.- Returns:
- a
Monocompleting once upserted or failed.
-
upsert
public Mono<MutationResult> upsert(String id, Object content, UpsertOptions options)
Upserts a full document which might or might not exist yet with custom options.- Parameters:
id- the document id to upsert.content- the document content to upsert.options- custom options to customize the upsert behavior.- Returns:
- a
Monocompleting once upserted or failed.
-
replace
public Mono<MutationResult> replace(String id, Object content)
Replaces a full document which already exists with default options.- Parameters:
id- the document id to replace.content- the document content to replace.- Returns:
- a
Monocompleting once replaced or failed.
-
replace
public Mono<MutationResult> replace(String id, Object content, ReplaceOptions options)
Replaces a full document which already exists with custom options.- Parameters:
id- the document id to replace.content- the document content to replace.options- custom options to customize the replace behavior.- Returns:
- a
Monocompleting once replaced or failed.
-
touch
public Mono<MutationResult> touch(String id, Duration expiry)
Updates the expiry of the document with the given id with default options.- Parameters:
id- the id of the document to update.expiry- the new expiry for the document.- Returns:
- a
MutationResultonce the operation completes.
-
touch
public Mono<MutationResult> touch(String id, Duration expiry, TouchOptions options)
Updates the expiry of the document with the given id with custom options.- Parameters:
id- the id of the document to update.expiry- the new expiry for the document.options- the custom options.- Returns:
- a
MutationResultonce the operation completes.
-
unlock
public Mono<Void> unlock(String id, long cas)
Unlocks a document if it has been locked previously, with default options.- Parameters:
id- the id of the document.cas- the CAS value which is needed to unlock it.- Returns:
- the mono which completes once a response has been received.
-
unlock
public Mono<Void> unlock(String id, long cas, UnlockOptions options)
Unlocks a document if it has been locked previously, with custom options.- Parameters:
id- the id of the document.cas- the CAS value which is needed to unlock it.options- the options to customize.- Returns:
- the mono which completes once a response has been received.
-
lookupIn
public Mono<LookupInResult> lookupIn(String id, List<LookupInSpec> specs)
Performs lookups to document fragments with default options.- Parameters:
id- the outer document ID.specs- the spec which specifies the type of lookups to perform.- Returns:
- the
LookupInResultonce the lookup has been performed or failed.
-
lookupIn
public Mono<LookupInResult> lookupIn(String id, List<LookupInSpec> specs, LookupInOptions options)
Performs lookups to document fragments with custom options.- Parameters:
id- the outer document ID.specs- the spec which specifies the type of lookups to perform.options- custom options to modify the lookup options.- Returns:
- the
LookupInResultonce the lookup has been performed or failed.
-
mutateIn
public Mono<MutateInResult> mutateIn(String id, List<MutateInSpec> specs)
Performs mutations to document fragments with default options.- Parameters:
id- the outer document ID.specs- the spec which specifies the type of mutations to perform.- Returns:
- the
MutateInResultonce the mutation has been performed or failed.
-
mutateIn
public Mono<MutateInResult> mutateIn(String id, List<MutateInSpec> specs, MutateInOptions options)
Performs mutations to document fragments with custom options.- Parameters:
id- the outer document ID.specs- the spec which specifies the type of mutations to perform.options- custom options to modify the mutation options.- Returns:
- the
MutateInResultonce the mutation has been performed or failed.
-
scan
@Volatile public Flux<ScanResult> scan(ScanType scanType)
Returns a stream ofScanResultsperforming a Key-Value range scan with default options.- Parameters:
scanType- the type or range scan to perform.- Returns:
- a Flux of
ScanResults(potentially empty). - Throws:
TimeoutException- if the operation times out before getting a result.CouchbaseException- for all other error reasons (acts as a base type and catch-all).
-
scan
@Volatile public Flux<ScanResult> scan(ScanType scanType, ScanOptions options)
Returns a stream ofScanResultsperforming a Key-Value range scan with custom options.- Parameters:
scanType- the type or range scan to perform.options- aScanOptionsto customize the behavior of the scan operation.- Returns:
- a Flux of
ScanResults(potentially empty). - Throws:
TimeoutException- if the operation times out before getting a result.CouchbaseException- for all other error reasons (acts as a base type and catch-all).
-
-