MongoDB C ++,如何在插入时添加ISODate值 [英] MongoDB C++, How to add ISODate value when inserting

查看:483
本文介绍了MongoDB C ++,如何在插入时添加ISODate值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是有关新的MongoDB C ++驱动程序(不是旧版驱动程序)的信息.我可以这样插入文档:

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

上面的代码插入一个文档,该文档具有值为'Value'的1个字段'Key'.我可以插入字符串,整数,浮点数...,但只是不知道如何插入ISODate.新的MongoDB C ++驱动程序应在文档中附带更多示例.

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,我发现了!

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

这篇关于MongoDB C ++,如何在插入时添加ISODate值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆