1

I'm working on project where i have to prepopulate array. I need to update this function so that arrays 'time' and 'values' become arrays with sub-arrays full of '0' but i can't figute it out how am i suppose to do this. I'll be grateful for any help!

int prepopulate(mongoc_collection_t *collection, int nvalues) {
    bson_t *doc, *values, *time;
    bson_error_t error;
    bson_oid_t oid;
    doc = bson_new ();
    values = bson_new ();
    time = bson_new();
    bson_oid_init (&oid, NULL);
    BSON_APPEND_OID (doc, "_id", &oid);
    BSON_APPEND_INT64 (doc, "series", 0);
    BSON_APPEND_INT64 (doc, "prevEnd", 0);
    BSON_APPEND_INT64 (doc, "nextStart", 0);
    int i;
    for (i=0; i<nvalues; i++) {
        BSON_APPEND_INT64(values, "0", 0);
        BSON_APPEND_INT64(time, "0", 0);
    }
    bson_append_array (doc, "value", -1, values);
    bson_append_array (doc, "time", -1, time);

    int res = mongoc_collection_insert(collection, MONGOC_INSERT_NONE, doc, 
    NULL, &error);

    bson_destroy (doc);
    bson_destroy (values);
    bson_destroy (time);
    return res;
}
chridam
  • 100,957
  • 23
  • 236
  • 235
Xander
  • 11
  • 1
  • 1
    Please start formatting your code. – Jabberwocky Mar 30 '17 at 11:33
  • please explain what your output is doing compared to what output you want, perhaps in json format – bauman.space Mar 30 '17 at 17:37
  • Now, these fields are filled with zeros ("series","prevEnd", "nextStart", "time", "values"). I need to change this code for fields "time" and "values" that each of them сonsisted of sub-arrays filled with zeros – Xander Mar 31 '17 at 09:47

0 Answers0