WriteError({"code":11000,"index":0,"errmsg":"E11000 duplicate key error collection: db.locationtracking index: _id_ dup key: { : \"cvnAdmcwb4PaeZx9b\" }","op":{"companyId":"","cardId":"","event":"Position","eventDateTime":"2019-04-26T19:39:18.000Z","resourceType":"Truck","resourceId":"1700","latitude":,"longitude":,"city":"","state":"","proximity":"","_id":"cvnAdmcwb4PaeZx9b"}})
at resultHandler (/home/site/wwwroot/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/bulk/ordered.js:459:11)
at handler (/home/site/wwwroot/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/topologies/replset.js:1209:22)
at /home/site/wwwroot/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb-core/lib/connection/pool.js:544:18
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
at endpoint: trucks/:id/position
Hey everyone, we’ve been trying to troubleshoot this issue for awhile now and we haven’t been able to come to a concrete solution. We are running 4 API servers that are running Meteor that are heavily using the Restivus package. There are no UI interactions on these servers. We have found that the issue is only happening on collections that have more than a few million documents in them. Our smaller collections have absolutely NO issues. This doesn’t make a lot of sense because the theoretical chances of running into a duplicate id using Meteor should be astronomical.
The _ids in Meteor.users consists of 17 characters (a-Z + 0-9). That gives you 17^44 = 1.379598e+54 combinations. If you would have a billion (10^9) documents in the collection, the risk of generating an existing _id would be 0.0000000000000000000000000000000000000000001%.
We have found people running into similar issues, but most seem to be around client and server sync problems and the other ones do not have a resolution. This dup key issue will start occurring after awhile on a single API instance and it won’t go away until we reboot the API server that is running into the issue. After a reboot the issue goes away and we might not see it for a week before it comes back.
Our insert statement uses the normal insert method for Meteor and we aren’t doing anything to this collection with collection hooks.
LocationTracking.insert();
Any thoughts or suggestions would be much appreciated!