#include#include using namespace bsoncxx; using namespace builder; int main() { // Create a BSON array builder bsoncxx::builder::basic::array arrBuilder; // Append some strings to the array arrBuilder.append(types::b_string{"Hello"}); arrBuilder.append(types::b_string{"World"}); // Get the BSON array document bsoncxx::document::value arrDoc = arrBuilder.extract(); return 0; }
#includeBoth of these examples demonstrate how to use the BSONArrayBuilder class to create a BSON array document by appending values to it one by one. The BSONCXX library also provides other classes for constructing BSON documents, such as BSONDocumentBuilder, which can be used to create more complex documents.#include using namespace bsoncxx; using namespace builder; int main() { // Create a BSON array builder bsoncxx::builder::basic::array arrBuilder; // Append some integers to the array arrBuilder.append(42); arrBuilder.append(23); arrBuilder.append(7); // Get the BSON array document bsoncxx::document::value arrDoc = arrBuilder.extract(); return 0; }