Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
Public Member Functions | Friends | List of all members
couchbase::collection Class Reference

Exposes collection-level kv operations. More...

#include <collection.hxx>

Public Member Functions

result get (const std::string &id, const get_options &opts=get_options())
 Get a document by key. More...
 
result exists (const std::string &id, const exists_options &opts=exists_options())
 Test existence of a document. More...
 
template<typename Content >
result upsert (const std::string &id, const Content &value, const upsert_options &opts=upsert_options())
 Upsert document. More...
 
template<typename Content >
result insert (const std::string &id, const Content &value, const insert_options &opts=insert_options())
 Insert document. More...
 
template<typename Content >
result replace (const std::string &id, const Content &value, const replace_options &opts=replace_options())
 Replace document. More...
 
result remove (const std::string &id, const remove_options &opts=remove_options())
 Remove document. More...
 
result mutate_in (const std::string &id, std::vector< mutate_in_spec > specs, const mutate_in_options &opts=mutate_in_options())
 Mutate some elements of a document. More...
 
result lookup_in (const std::string &id, std::vector< lookup_in_spec > specs, const lookup_in_options &opts=lookup_in_options())
 Lookup some elements of a document. More...
 
CB_NODISCARD const std::string & name () const
 Get name of collection. More...
 
CB_NODISCARD const std::string & scope () const
 Name of scope for this collection. More...
 
CB_NODISCARD const std::string & bucket_name () const
 Get name of bucket for this collection. More...
 
CB_NODISCARD std::shared_ptr< couchbase::bucketget_bucket ()
 Get bucket for this collection. More...
 
CB_NODISCARD std::chrono::microseconds default_kv_timeout () const
 Return default timeout for the kv operations. More...
 

Friends

class bucket
 
result store_impl (collection *coll, store_operation op, const std::string &id, const std::string &payload, uint64_t cas, durability_level level, std::chrono::microseconds timeout)
 

Detailed Description

Exposes collection-level kv operations.

Examples:
examples/game_server.cxx.

Member Function Documentation

◆ bucket_name()

CB_NODISCARD const std::string& couchbase::collection::bucket_name ( ) const
inline

Get name of bucket for this collection.

Returns
Name of bucket for this collection.

◆ default_kv_timeout()

CB_NODISCARD std::chrono::microseconds couchbase::collection::default_kv_timeout ( ) const
inline

Return default timeout for the kv operations.

Returns
Default kv timeout.
See also
cluster_options::kv_timeout for setting this, and
common_options::timeout to use a different timeout on an operation.

◆ exists()

result couchbase::collection::exists ( const std::string &  id,
const exists_options opts = exists_options() 
)

Test existence of a document.

Parameters
idKey of document.
optsOptions for this command.
Returns
result The result::value will be true if document exists, false otherwise.

◆ get()

result couchbase::collection::get ( const std::string &  id,
const get_options opts = get_options() 
)

Get a document by key.

Returns a result containing document if a document with that key exists, otherwise the result will contain the error.

Parameters
idKey of document to get.
optsOptions to use for this command.
Returns
result The result of the operation. See result.
Examples:
examples/game_server.cxx.

◆ get_bucket()

CB_NODISCARD std::shared_ptr<couchbase::bucket> couchbase::collection::get_bucket ( )
inline

Get bucket for this collection.

Returns
bucket for this collection.

◆ insert()

template<typename Content >
result couchbase::collection::insert ( const std::string &  id,
const Content &  value,
const insert_options opts = insert_options() 
)
inline

Insert document.

Inserts a new document with the Content given.

Parameters
idKey of document to insert.
valueThe document itself. Note that the object either needs to be an nlohmann::json object or there needs to be to/from_json functions defined for it.
optsOptions to use when inserting. For instance, you can set a durability. See insert_options.
Returns
Result of the operation.

◆ lookup_in()

result couchbase::collection::lookup_in ( const std::string &  id,
std::vector< lookup_in_spec specs,
const lookup_in_options opts = lookup_in_options() 
)

Lookup some elements of a document.

Lookup some elements in a document. See lookup_in_spec for the various possibilities and limitations. Useful when you don't want to fetch and parse entire document.

Parameters
idKey of doc to mutate.
specsVector of specs that represent the mutations.
optsOptions to use when mutating. You can specify a durability or cas, for instance. See mutate_in_options.
Returns
Result of operation.

◆ mutate_in()

result couchbase::collection::mutate_in ( const std::string &  id,
std::vector< mutate_in_spec specs,
const mutate_in_options opts = mutate_in_options() 
)

Mutate some elements of a document.

Mutates some paths within a document. See mutate_in_spec for the various possibilities and limitations. Useful avoiding constructing, sending entire document, if all you want to do is modify a small fraction of it.

Parameters
idKey of doc to mutate.
specsVector of specs that represent the mutations.
optsOptions to use when mutating. You can specify a durability or cas, for instance. See mutate_in_options.
Returns
Result of operation.

◆ name()

CB_NODISCARD const std::string& couchbase::collection::name ( ) const
inline

Get name of collection.

Returns
Name of collection. Note the default collection is named "_default".

◆ remove()

result couchbase::collection::remove ( const std::string &  id,
const remove_options opts = remove_options() 
)

Remove document.

Removes an existing document.

Parameters
idKey of document to remove.
optsOptions to use when removing. For instance, you can set a durability or cas. See remove_options.
Returns
Result of the operation.

◆ replace()

template<typename Content >
result couchbase::collection::replace ( const std::string &  id,
const Content &  value,
const replace_options opts = replace_options() 
)
inline

Replace document.

Replaces an existing document with the Content given.

Parameters
idKey of document to replace.
valueThe document itself. Note that the object either needs to be an nlohmann::json object or there needs to be to/from_json functions defined for it.
optsOptions to use when replacing. For instance, you can set a durability or cas. See replace_options.
Returns
Result of the operation.

◆ scope()

CB_NODISCARD const std::string& couchbase::collection::scope ( ) const
inline

Name of scope for this collection.

Returns
Scope of collection. Note default scope is "_default".

◆ upsert()

template<typename Content >
result couchbase::collection::upsert ( const std::string &  id,
const Content &  value,
const upsert_options opts = upsert_options() 
)
inline

Upsert document.

Inserts a new document or replaces an existing document, with the Content given.

Parameters
idKey of document to upsert.
valueThe document itself. Note that the object either needs to be an nlohmann::json object or there needs to be to/from_json functions defined for it.
optsOptions to use when upserting. For instance, you can set a durability. See upsert_options.
Returns
Result of the operation.
Examples:
examples/game_server.cxx.

The documentation for this class was generated from the following file: