MongoDB C++, How to add ISODate value when inserting

做~自己de王妃 提交于 2019-12-07 17:18:45

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/40797650/mongodb-c-how-to-add-isodate-value-when-inserting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!