2016-11-25 86 views
3

这是关于新的MongoDB C++驱动程序(不是传统的)。我可以这样插入一个文档:MongoDB C++,如何在插入时添加ISODate值

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

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

上面的代码插入一个带有'Value'字段'Key'的字段的文档。我可以插入字符串,int,float,...但只是不知道如何插入ISODate。新的MongoDB C++驱动程序应该附带更多文档示例。

+1

['bsoncxx ::类型:: B_DATE'](http://mongodb.github.io/mongo-cxx-driver/api/mongocxx-3.0.3/structbsoncxx_1_1types_1_1b__date.html) – styvane

回答

3

感谢Styvane,我发现它怎么样!

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

cxxClient["db"]["collection"].insert_one(Value.view()); 
相关问题