Chiming in with another instance where you might encounter this issue.
If you’re using
Random.id()… probably anywhere, but in my specific case… to generate client-side
_id's as part of a JSON browser cache setup, be sure to strip these ID’s before committing data to MongoDB as it’s nowhere near random enough.
We started encountering duplicate ID issues after only a couple years of operation (and around 2000 data entries). Took me a few hours to figure out why we were getting duplicate ID errors. And of course, because it was cached form data, once a user-generated an
_id for submission even refreshing the page wouldn’t change that ID so it was impossible to get around it from a users perspective.
Protip, if you’re using Meteor (you’re here I guess but you never know), the underscore library bundled with Meteor has a lovely omit function that’s cleaner than the native
delete data._id option. Usage:
_.omit(data,'_id') returns a JSON object minus the key specified, in this instance
'_id', without modifying the source object. This is very handy for avoiding orphaning of data in the cache so it can be properly removed upon a successful insert.
Edit: Oh yeah fun fact. The duplicate ID’s that were generated conflicted with the same users other entries, exclusively so far as I can tell, not recent entries either. Says something about how nonrandom