Solve race conditions in getCollection method.