5

This is about the new MongoDB C++ Driver (not the legacy one). I can insert a document this way:

value Value = document{}
<<"Key" <<"Value"
<<finalize;

cxxClient["db"]["collection"].insert_one(Value.view());

The above code insert a document with 1 field 'Key' of value 'Value'. I can insert string, int, float,... but just can't figure out how to insert ISODate. The new MongoDB C++ Driver should come with more examples in documentation.

styvane
  • 59,869
  • 19
  • 150
  • 156
Dee
  • 7,455
  • 6
  • 36
  • 70
  • 1
    [`bsoncxx::types::b_date `](http://mongodb.github.io/mongo-cxx-driver/api/mongocxx-3.0.3/structbsoncxx_1_1types_1_1b__date.html) – styvane Nov 25 '16 at 04:39

1 Answers1

9

Thanks Styvane, I found it out how!

value Value = document{}
<<"Key" <<"Value"
<<"Date" <<bsoncxx::types::b_date(std::chrono::system_clock::now())
<<finalize;

cxxClient["db"]["collection"].insert_one(Value.view());
Dee
  • 7,455
  • 6
  • 36
  • 70