LibBSON export to buffer

233 Views Asked by At

I'm searching for a way to copy a BSON document to a buffer or into a file using the C-library libbson.

I think I'm missing something - any help is appreciated.

2

There are 2 best solutions below

0
zille On

bson_as_canonical_extended_json exports BSON into UTF-8 without loss of information.

0
Richard On

If you only need buffer data, you can use bson_get_data :

bson_t * bson = bson_new();
///// Fill with data

// Get data buffer
const char * data = reinterpret_cast<const char*>(bson_get_data(bson));
int length = bson->len;