oatpp / oatpp-mongo

Oat++ native BSON + MongoDB driver implementation based on Oat++ object-mapping sub-framework.
https://oatpp.io/
Apache License 2.0
6 stars 4 forks source link

How do I define a DTO field as int64 and mapped to MongoDB DateTime? #10

Closed ns-wxin closed 1 year ago

ns-wxin commented 1 year ago

I'm having difficulty finding an example to define a DTO field and map it to MongoDB as DateTime. The example in this repo doesn't have such field.

With a uint64, it's mapped a timestamp which is not quite what I want. I'm getting compiler error if I do the following complaining "DateTime" is not a defined type.

class MyGroup : public oatpp::DTO {
    DTO_INIT(FingerprintGroup, DTO)

    DTO_FIELD(String, _id);

    DTO_FIELD(String, fpGroupName);
    DTO_FIELD(String, status);
    DTO_FIELD(String, type);
    DTO_FIELD(Int32, version) = 0;
    DTO_FIELD(DateTime, created) = 0L;
    DTO_FIELD(DateTime, updated) = 0L;
};
ns-wxin commented 1 year ago

Sorry, I figured out that I have to include <oatpp-mongo/bson/Types.hpp>

do using oatpp::mongo::bson::DateTime;

closing it.