遇到一个棘手的问题
我想构造的数据库如下
{
_id:***
videoName:***
flag:***
features: [
{
data:***
timestamp:***
}
{
data:***
timestamp:***
}
{
……
}
]
}
我使用bsoncxx::builder::stream::document流式构造了整个文档,想在每次执行提取一帧特征的函数的时候将特征加入到features数组中,在网上没找到好的答案,基本上都是bsoncxx::builder::basic里面的处理,比较麻烦。
我的代码
videoCollection = collection;
videoDocument<<"videoName"<<fileList[videoPath]<<"flag"<<"advertisement";//videoDocument是bsoncxx::builder::stream::document类型
videoCollection.insert_one(videoDocument.view());
//一开始并不写入features数组
然后在我提取每帧特征的函数里
using bsoncxx::builder::stream::open_document;
using bsoncxx::builder::stream::close_document;
bsoncxx::builder::stream::document addDocBuilder;
bsoncxx::builder::stream::document singleFeature;
singleFeature<<"data"<<bufCDVS.data<<"timestamp"<<frame->pts;
addDocBuilder<<"$push"<<open_document<<"features"<<singleFeature<<close_document;
//使用$push指定features为所要添加元素的数组的名称,如果没有会新建一个。
//注意open_document和close_document是必不可少的的,且需要使用using
videoCollection.update_one(videoDocument.view(),addDocBuilder.view());
//使用update_one方法更新这个文档
最终的结果(使用robo3t做可视化工具)
Ubuntu screenshot挂了,补截图。