我如何将 c++ 中的向量序列化为 char,以便于将 mondodb 用于后端
How I can serialize vector in c++ to char for easy using mondodb for backend
我有vector<matrix<float,o,1>> obj_id;
矩阵为:
class matrix : public matrix_exp<matrix<T,num_rows,num_cols, mem_manager,layout> >
我想把每个项目都写给mongodb。我找不到转换的解决方案。
但是我可以序列化每个项目来编写mongodb。但大多数序列化当然是文件。
如何序列化为 char 或任何方便的变量以将 mongodb 作为二进制插入?
最好
免责声明:自从我在C++领域工作以来已经有一段时间了,但向量本质上是一个数组,您可以使用 MongoDB 站点上的 BSON 文档生成器示例让 Cxx 驱动程序遍历数组并构造文档:
https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/working-with-bson/
要获得对矢量的类似数组的访问,请执行以下操作:
if(obj_id.size()) {
// create the pointer to the array
double *myarray = &obj_id[0];
// create a bson array builder and populate
auto array_builder = bsoncxx::builder::basic::array{};
for (const auto& element : elements) {
array_builder.append(element);
}
// Add the array_builder result into a document
// and save into the database
...
}
同样,我的C++有点生疏,我对MongoDB Cxx驱动程序的经验更加有限,但我希望您有足够的指针/开始继续您的工作。
相关文章:
- ArrayFire中统一后端的使用
- 有没有办法知道Tracer是否成功地完全连接到了jaegerclientcpp中的jaeger后端服务器
- 如何在 LLVM 后端的机器级别找到 def-use 链
- 如何在 boost::msm 中实现可以访问状态机 (SM) 的后端/前端的"BaseState"
- 在单链表中的后端插入节点
- CUDA(GPU)作为OpenCV后端
- 如何将C 中的后端写入与TCL/TCK用户界面连接
- 在同一应用程序中,可以将C 用作后端和Javafx
- 是否可以使用 c++ 作为 Electron.js 的后端
- 我如何将 c++ 中的向量序列化为 char,以便于将 mondodb 用于后端
- 当后端响应需要很长时间时,WXWIDGET应用程序会挂起
- Boost ::使用与多个水槽的同一后端使用相同的后端安全性
- 从Web前端发送请求到C 后端
- 无法使用CPU后端使用TensorFlow AOT编译创建最终二进制文件
- Skia中的非均匀文本缩放(Freetype 2后端)
- 带有C 类的Electron Nodejs在后端
- 用于C++后端服务的 Web 界面
- 在不减慢主应用程序速度的情况下在后端运行成员函数的技巧是什么
- 在Boost Meta状态机的后端访问前端
- C++11线程实现后端