0

I am using MongoDB with the c-client, mongoc 1.8.1.

I am performing a bulk update, with 6 mongoc_bulk_operation_update_one() operations. However, for 3 of the updates the selection document does not match anything in the database (say query1,query2,query3).

...
mongoc_bulk_operation_t* pBulk = mongoc_collection_create_bulk_operation(coll_,false,NULL); //unorderd

mongoc_bulk_operation_update_one(pBulk,&query1,&document,false);
mongoc_bulk_operation_update_one(pBulk,&query2,&document,false);
mongoc_bulk_operation_update_one(pBulk,&query3,&document,false);
mongoc_bulk_operation_update_one(pBulk,&query4,&document,false);
mongoc_bulk_operation_update_one(pBulk,&query5,&document,false);
mongoc_bulk_operation_update_one(pBulk,&query6,&document,false);

bson_t reply;
bson_error_t error;
uint32_t ret = mongoc_bulk_operation_execute(pBulk,&reply,&error);

if (ret) {
    str = bson_as_canonical_extended_json (&reply, NULL);
    printf ("%s\n", str);
    bson_free (str);
}

The reply document counts the number matched and modified correctly (3):

reply={ "nInserted" : { "$numberInt" : "0" }, "nMatched" : { "$numberInt" : "3" }, "nModified" : { "$numberInt" : "3" }, "nRemoved" : { "$numberInt" : "0" }, "nUpserted" : { "$numberInt" : "0" }, "writeErrors" : [  ] };

but does not give a clue on which updates did NOT match.

Is there a way to perform this operation in a way that will give me the indices of the updates that did not match?

YTock
  • 1
  • 1
  • Have you looked into something like `findAndModify()` ? – Alex P. Nov 22 '17 at 15:10
  • findAndModify cannot be used in a bulk operation. It is of course possible to achieve what I am looking for in a variety of single operations. But for performance reasons I am looking for a way to do this in a bulk. – YTock Nov 23 '17 at 12:08
  • Yeah, that's why I said "something like", I'm aware it's not for bulk. Take a look into this answer, maybe you can find something that fit's to your needs:https://stackoverflow.com/questions/40124496/mongo-bulk-find-and-update-matched-documents-field-in-single-query . Update alone though does not return any results – Alex P. Nov 23 '17 at 13:38
  • @Alex P. with update as a single operation you can call get_last_error() and figure out if it matched or not. The link you cite does not help in this regard. Again I am trying to do this is a bulk. I guess it is not supported. Thanks – YTock Dec 03 '17 at 09:47

0 Answers0