Best way to insert document with id's from other recently created collections

I’m building a logic that basically uploads documents to one or several collection in MongoDb from an excel file.

Sometimes, the own excel file insert new documents whose ID will be a paramater value from other documents. For example, one sheet contains customers and the next one invoices, so when the invoice is being sent, inserted to MongoDB, it shoud have the parameter customer changed from the string (the one used in the previouse sheet to insert the customer) to the ObjectId that the customer document was created with.

Other times, the customer is not in excel but already in the database. Other in neither, so the customer parameter will be the plain string supplied.

Now I’m using triggers for the job. But I couldn’t figure out a way to perform with this approach combined with the bulkWrite to update thousands to millions of documents and I think that sometimes there is quite some randomness with the update of the parameters.