Ditto  1.0.14
Public Member Functions | List of all members
ditto::DocumentId Struct Reference

An identifier for a Document. More...

Public Member Functions

 DocumentId (nlohmann::json id_value)
 Creates a new DocumentId. More...
 
bool operator== (const DocumentId &rhs) const
 
bool operator!= (const DocumentId &rhs) const
 
DocumentIdPath operator[] (std::string key) const
 Used to specify a path to a key in the document ID that you can subscript further to access a nested key in the document ID. More...
 
DocumentIdPath operator[] (std::size_t index) const
 Used to specify an index in the array at the preceding key-path specified through the subscripting defined previously. You can subscript the return value further to access a further nested key in the document ID. More...
 
bool empty ()
 Returns whether or not the document ID is empty (and therefore invalid). More...
 
nlohmann::json value () const
 Get the underlying value of the document identifier as a native type. More...
 
std::string to_string () const
 Returns a stringified representation of a document identifier. More...
 
nlohmann::json to_native () const
 

Detailed Description

An identifier for a Document.

Each DocumentId represents a unique identifier for a document.

Constructor & Destructor Documentation

◆ DocumentId()

ditto::DocumentId::DocumentId ( nlohmann::json  id_value)
explicit

Creates a new DocumentId.

A document ID can be created from any of the following:

  • string
  • integer
  • boolean
  • null
  • byte array
  • array (containing any of the items in this list)
  • map (where the keys must be strings and the values can be made up of any of the items in this list)

Note that you cannot use floats or other custom types to create a document ID.

Document IDs are also limited in size, based on their serialized representation, to 256 bytes. You will receive an error if you try to create a document ID that exceeds the size limit.

Parameters
[in]valuethe value that represents the document identifier.
Returns
a DocumentId that uniquely identifies a Document.

Member Function Documentation

◆ empty()

bool ditto::DocumentId::empty ( )

Returns whether or not the document ID is empty (and therefore invalid).

Returns
a bool representing whether or not the document ID is empty (and therefore invalid).

◆ operator[]() [1/2]

DocumentIdPath ditto::DocumentId::operator[] ( std::size_t  index) const

Used to specify an index in the array at the preceding key-path specified through the subscripting defined previously. You can subscript the return value further to access a further nested key in the document ID.

Parameters
[in]indexthe index of the array that you wish to access in the key previously specified with the preceding subscripting.

◆ operator[]() [2/2]

DocumentIdPath ditto::DocumentId::operator[] ( std::string  key) const

Used to specify a path to a key in the document ID that you can subscript further to access a nested key in the document ID.

Parameters
[in]keythe next part of the path needed to get to the key in the document ID you wish to get the value of.

◆ to_native()

json ditto::DocumentId::to_native ( ) const
Deprecated:
Deprecated since version 1.0.2 of the SDK. You should use value() instead.

◆ to_string()

std::string ditto::DocumentId::to_string ( ) const

Returns a stringified representation of a document identifier.

The returned string can be used directly in queries that you use with other Ditto functions. For example you could create a query that was like this:

my_collection.find("_id == " + doc_id.to_string())
Returns
a stringified representation of the document identifier.

◆ value()

json ditto::DocumentId::value ( ) const

Get the underlying value of the document identifier as a native type.

Returns
the underlying value of the document identifier as a native type.