Abort when trying to append large array to bsoncxx document

Hello everyone,

I wonder whether there is any fixed size limit for bsoncxx documents. I am aware that documents can be stored in MongoDB up to 16MB only, so I wonder about any potential limit for in-memory operations.

The code is as follows:

auto n1 = new bsoncxx::builder::basic::array();
auto n2 = new bsoncxx::builder::basic::array();
auto n3 = new bsoncxx::builder::basic::array();
auto n4 = new bsoncxx::builder::basic::array();

for (auto tet : tets)
{
	size_t n[4];
	tet.getNodes(n);

	n1->append((long long) n[0]);
	n2->append((long long) n[1]);
	n3->append((long long) n[2]);
	n4->append((long long) n[3]);
}

storage.append(bsoncxx::builder::basic::kvp("Node1", *n1));
storage.append(bsoncxx::builder::basic::kvp("Node2", *n2));
storage.append(bsoncxx::builder::basic::kvp("Node3", *n3));    <---- Abort here
storage.append(bsoncxx::builder::basic::kvp("Node4", *n4));

delete n1; n1 = nullptr;
delete n2; n2 = nullptr;
delete n3; n3 = nullptr;
delete n4; n4 = nullptr;

When trying to append “Node3”, the software “Aborts” in ucrtbased.dll. The computer still has enough memory available at this time. The document “storage” is created on the heap via “new”.

The “tets” std::array has a total of 21.732.285 entries, so the document becomes rather large. However, the document will later on be stored by using GridFS. Slightly smaller document sizes work fine.

Any ideas what can go wrong here?

Thanks a lot for you help!