globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 232 forks source link

Bulk upserts does not report upserted IDs #367

Open smaurel opened 5 years ago

smaurel commented 5 years ago

The bulk result structure does not contain UpsertedIDs, so it is impossible to know what IDs were inserted when upserting using bulk upsert.

The fact that this feature is missing is a problem for requests such as the following one, when I want to do something with IDs that were inserted.

db.my_collection.bulkWrite([{"updateOne": {"filter": {"not_id_field" : "10000000"}, "update": {"$setOnInsert": {"_id": "some_random_id"},"$addToSet": {"other_field": {"$each": ["100"]}}}, "upsert": true }}])

{ "acknowledged" : true, "deletedCount" : 0, "insertedCount" : 0, "matchedCount" : 0, "upsertedCount" : 1, "insertedIds" : {}, "upsertedIds" : { "0" : "some_random_id" } }

Request result comes from Mongo 4.0.6 EDIT: The request result is the same using Mongo 3.6.8

Wouldn't it be more complicated than just adding the upsertedIDs field in BulkUpdate structure and using the field in the Bulk's runUpdate method?