1

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.

2 Answers 2

1

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], ...);

Sign up to request clarification or add additional context in comments.

1 Comment

how can i pass full array , as i dont know how many elements i have im converting vector to array
0

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), "}");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.