Hey guys, can you guys help me with an issue using mongo?
I have a database, that has 4 fields, and I register more than 100k new registers in a day, and I was having a lot of performance issues checking if the register it’s already created(to prevent duplicate registers).
If your use case requires unique indexes, the main consideration is correctness rather than performance.
Unnecessary indexes will be unhelpful for performance as they take up RAM and add a bit of write I/O. Useful indexes will support common queries.
The general approach you are taking with two separate commands (find followed an insert) is subject to race conditions. The recommended pattern would be to Insert or Update in a Single Operation using an upsert.