{
students: {
"employee": 99,
"name": "myname",
"status": "mystatus",
"totmarks": 99
}
}
{
_id: ObjectID("55ed34ef4a2e2b4416656fa1"),
students : {
"employee": 99,
"name": "myname",
"status": "mystatus",
"totmarks": 99
}
}
#include <mongoc.h>
#include <bson.h>
bson_t *doc;
doc = bson_new ();
bson_t subdoc;
BSON_APPEND_DOCUMENT_BEGIN(doc, "students", &subdoc);
BSON_APPEND_INT32(&subdoc, "employee", 99);
BSON_APPEND_UTF8(&subdoc, "name", "myname");
BSON_APPEND_UTF8(&subdoc, "status", "mystatus");
bson_append_document_end(doc, &subdoc);
#include <mongoc.h>
#include <bson.h>
bson_t *doc;
doc = BCON_NEW ("students", "{",
"employee", BCON_INT32(99),
"name", BCON_UTF8("myname"),
"status", BCON_UTF8("mystatus"),
"}");
> Hi Wan, Thanks for your response.
> I have tried the first approach that you have suggested i.e to use BSON_APPEND_* methods to store the members of C sturcture.
> This method id ok if structure contains less number of items in C structure. In my case, the structure would contain around 150 members. Therfore it is tedious
> to use BSON_APPEND_* methods for all members of structure.
> Is there any BSON_APPEND_* API which can take object/structure as parameter to store into MongoDB?
> Can you please guide me?