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

Types: Add DateTime support. #4

Closed lganzzzo closed 4 years ago

lganzzzo commented 4 years ago

Now BSON DateTime data type is supported.

  #include "oatpp-mongo/bson/Types.hpp"

  ...

  auto duration = std::chrono::system_clock::now().time_since_epoch();
  auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();

  collection.insert_one(createMongoDocument(
    oatpp::Fields<oatpp::Any>({
        {"time", oatpp::mongo::bson::DateTime(millis)}
    })
  ));

Inserted document:

_id: ObjectId("5f9b6ecb21a7da049662e7d2")
time: 2020-10-30T01:39:23.940+00:00

Links: