Generate unique string type _id during an aggregation for multiple documents

I am transforming a bunch of our data from one collection and creating a new collection from it. Our database uses String type _id as the unique key so using the default key creation on $out / $merge is not possible as it creates ObjectIds. Is there a way I can set my own String _id or create a random String sequence to use for this instead?

The idea here is NOT to make round trips to and from the server and database. I could of course pull it all down add new _ids individually and insert but this is a large dataset and I want to avoid that if possible.

Also I have looked into mapReduce which would allow me to do this but then I end up with a funny document shape where the fields are all under ‘value’ and I would need to reshape them all.

I’ve also looked into just setting an _id in the aggregation using ObjectId().str or similar but it only executes this code once meaning each _id is identical.

Perhaps this isn’t possible but would love to know your thoughts/tips

Was there any resolution to this? I think I’m running into the same problem. I tried using $addFields in the aggregation before $merge to create a new _id: ObjectId().valueOf(), but it seems to want to insert the same ObjectId for every single record, which was a bit unexpected.

Anyone else have any suggestions for how to approach this?