Reputation: 137
Until Last month, I was using Legacy C Driver but from last week i shifted to the new C Driver, which looks quite good and easy to use. I saved a document in the DB like which have 3 strings, 2 integers and 2 arrays. Now i want to update this array. I am trying like this,
update_mod = BCON_NEW ("$set", "{",
"Int1", BCON_INT32 (23),
"Int2",BCON_INT32(34),
"String1",BCON_UTF8("String1"),
"String2", BCON_UTF8("String2"),
"String3",BCON_UTF8("String3"),
"Array1", BCON_ARRAY(&Array1),
"Array2", BCON_ARRAY(&Array2),
"}");
}
But it's not working, if i try to update it without Array then it's working perfectly. Can anyone tell me how i can do this. and also i want to save multiple values in Array for each update.
Upvotes: 1
Views: 467
Reputation: 2685
You can pass a variable of type bson_t to BCON_ARRAY. So, first you will create a BCON_DOCUMENT from your array and then you can pass that document as an input to BCON_ARRAY; something like below:
bson_error_t error;
bson_t *bson_array_doc = bson_new_from_json((const uint8_t *)my_array_str, -1, &error);
bson_t *bson_doc = BCON_NEW("$set", "{", "my_array", BCON_ARRAY(bson_array_doc), "}");
Upvotes: 0
Reputation: 172
BCON_ARRAY uses as input a list of args, not a pointer to an array. You should use something like:
BCON_ARRAY( Array1[0], Array1[1], ...);
Upvotes: 1