Ditto 5.0.0
Loading...
Searching...
No Matches
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.
 
bool operator== (const DocumentId &rhs) const
 
bool operator!= (const DocumentId &rhs) const
 
bool empty () const
 Returns whether or not the document ID is empty (and therefore invalid).
 
nlohmann::json value () const
 Get the underlying value of the document identifier as a native type.
 
std::string to_string () const
 Returns a stringified representation of a document identifier.
 

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 ( ) const

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).

◆ 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()

nlohmann::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.