template<typename Collection, typename Function>bsoncxx::array::value convert(Collection const & collection, Function function){ bsoncxx::builder::stream::array array; for (auto && entry : collection) { function(array, std::forward<decltype(entry)>(entry)); } return array.extract();}
using bsoncxx::builder::stream::document;using bsoncxx::builder::stream::finalize;
struct Foo{ Foo(int a, int b) : _a{a}, _b{b} {} int _a; int _b;};
using FooVec = std::vector<Foo>;
FooVec fooVec = { {1, 2}, {3, 4} };
const auto doc = (document{} << "Array" << bsoncxx::types::b_array { convert(fooVec, [](bsoncxx::builder::stream::array & array, FooVec::value_type const & foo) { array << bsoncxx::types::b_document { (document{} << "A" << foo._a << "B" << foo._b << finalize) }; }) } << finalize);
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/d79f5b05-16a6-4cfc-a7a7-b49de20ae6db%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
{ name : "Jason Carey",
title : "Software Engineer",
location : "New York, NY",
twitter : ["@MongoDB", "@MongoDBInc"],
facebook : ["MongoDB", "MongoDB, Inc."] }
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/f6effa86-053d-4c55-a73e-d05f3dee2fd2%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/9bee2aa5-6f5f-4056-af02-267d00beecc4%40googlegroups.com.