I have big amounts of documents and I need to assign to them certain codes dynamically (by this I mean not all at once, but any code at any given time). These codes keep a specific format and must be unique for every document.
My question is: Is it better to make a view that emits all the codes from all the documents and check said view before assigning the document (maybe even on a sync function) to see if the code is already in use, or is it better to create documents with the code as an id and a reference to the document they have been assigned to, and just check if the document already exists?
The latter option sounds faster since we are talking about a lot of documents (in the hundreds of thousands potentially) and a view would have a bad time keeping up with the updates. On the other hand, potentially doubling up the amount of documents doesn’t seem appealing either.
I also have a third option which consists of having special documents with an assigned range of codes, which would contain a map with all the assigned codes within their range and the documents they have been assigned to. This however seems like it would make for a lot of conflicts as many users would access those documents simultaneously.