Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
Click here >
Docs Menu
Docs Home
/ /
Datos del modelo

Supported Types - C++ SDK

The Realm C++ SDK currently supports these property types.

Los opcionales utilizan la plantilla de clase std::opcional.

You can use the following types to define your object model properties.

Para aprender cómo se asignan tipos de datos específicos a los BSON types en un esquema de App Services, consulta Mapeo del modelo de datos en la documentación de Atlas App Services.

Tipo
Requerido
Opcional

bool

bool boolName;
std::optional<bool> optBoolName;

Int64

int64_t intName;
std::optional<int64_t> optIntName;

Double

double doubleName;
std::optional<double> optDoubleName;

String

std::string stringName;
std::optional<std::string> optStringName;

enum

Enum enumName;
std::optional<Enum> optEnumName;

Datos binarios

std::vector<std::uint8_t> binaryDataName;
std::optional<std::vector<std::uint8_t>> optBinaryDataName;

fecha

std::chrono::time_point<std::chrono::system_clock> dateName;
std::optional<std::chrono::time_point<std::chrono::system_clock>> optDateName;

Decimal128

realm::decimal128 decimal128Name;
std::optional<realm::decimal128> optDecimal128Name;

UUID

realm::uuid uuidName;
std::optional<realm::uuid> optUuidName;

Object ID

realm::object_id objectIdName;
std::optional<realm::object_id> optObjectIdName;

Mixed Data Type

realm::mixed mixedName;

N/A

Map

std::map<std::string, SomeType> mapName;

N/A

Lista

std::vector<SomeType> listTypeName;

N/A

Configura

std::set<SomeType> setTypeName;

N/A

User-defined Object

N/A

MyClass* opt_obj_name;

User-defined Embedded Object

N/A

MyEmbeddedClass* opt_embedded_object_name;

Some of the supported types above are aliases for:

  • mixedUn objeto similar a una unión que puede representar un valor de cualquiera de los tipos admitidos. Se implementa mediante la plantilla de clase std::variant. Esta implementación significa que una mixed propiedad contiene un valor de uno de sus tipos alternativos o, en caso de error, ningún valor.

  • Para las fechas, utiliza la librería chrono para almacenar un time_point relativo a la system_clock: <std::chrono::time_point<std::chrono::system_clock>>

The Map is an associative array that contains key-value pairs with unique keys.

You can declare a Map as a property of an object:

namespace realm {
struct Dog {
std::string name;
std::map<std::string, std::string> favoriteParkByCity;
};
REALM_SCHEMA(Dog, name, favoriteParkByCity)
} // namespace realm

String is the only supported type for a map key, but map values can be:

  • Required versions of any of the SDK's supported data types

  • Optional user-defined object links

  • Optional embedded objects

Realm disallows the use of . or $ characters in map keys. You can use percent encoding and decoding to store a map key that contains one of these disallowed characters.

// Percent encode . or $ characters to use them in map keys
auto mapKey = "Monday.Morning";
auto encodedMapKey = "Monday%2EMorning";

Realm has several types to represent groups of objects, which we call collections. A collection is an object that contains zero or more instances of one Realm type. Realm collections are homogenous: all objects in a collection are of the same type.

You can filter and sort any collection using Realm's query engine. Collections are live, so they always reflect the current state of the realm instance on the current thread. You can also listen for changes in the collection by subscribing to collection notifications.

La colección de resultados del SDK de C++ es un tipo Results que representa los objetos recuperados de las consultas. Una colección representa los resultados evaluados de forma diferida de una operación de consulta. Los resultados son inmutables: no se pueden añadir ni eliminar elementos de la colección. Los resultados tienen una consulta asociada que determina su contenido.

For more information, refer to the Read documentation.

La colección de conjuntos del C++ SDK representa una relación de uno a muchos que contiene valores distintos. Un set SDK de C++ admite los siguientes tipos (y sus versiones opcionales):

  • Datos binarios

  • bool

  • Double

  • fecha

  • Int64

  • Mezclado

  • ObjectId

  • Objeto

  • String

  • UUID

Like the C++ std::set, the C++ SDK set is a generic type that is parameterized on the type it stores.

You can only call set mutation methods during a write transaction. You can register a change listener on a mutable set.

El SDK de C++ también ofrece varios tipos de colecciones que puedes usar como propiedades en tu modelo de datos:

  1. List, a type representing to-many relationships in models.

  2. Set, a type representing to-many relationships in models where values are unique.

  3. linking_objects, un tipo que representa relaciones inversas en los modelos.

  4. Map, a type representing an associative array of key-value pairs with unique keys.

Like live objects, Realm collections are usually live:

  • Live results collections always reflect the current results of the associated query.

  • Live lists always reflect the current state of the relationship on the realm instance.

The one case when a collection is not live is when the collection is unmanaged. For example, a List property of a Realm object that has not been added to a realm yet or that has been moved from a realm is not live.

Combinado con notificaciones de colección, las colecciones en tiempo real permiten un código limpio y reactivo. Por ejemplo, supón que tu vista muestra los resultados de una query. Puedes mantener una referencia a la colección de resultados en tu código vista, y luego leer la colección de resultados según sea necesario sin tener que actualizarla o validar que esté actualizada.

Importante

Results indexes may change

Dado que los resultados se actualizan automáticamente, no se debe almacenar el índice posicional de un objeto en la colección ni la cuenta de objetos en una colección. El índice almacenado o el valor de la cuenta podría estar desactualizado para cuando lo utilices.

Volver

Object Types and Schemas

En esta página