    protected <T> MongoCollection<T> collection(Class<T> entityClass) {
        class TAtomicOperation extends AtomicOperation<T> {
            public TAtomicOperation(Datastore ds, Query<T> query, boolean multiple) {
                super(ds, query, multiple);
            }
        }
        class TMongoCollection extends MongoCollection<T> {
            public TMongoCollection(Class<T> entityClass, Datastore ds) {
                super(entityClass, ds);
            }
            @Override
            public AtomicOperation<T> atomic(Filter... filters) {
                return new TAtomicOperation(ds, query(filters), false);
            }
            @Override
            public AtomicOperation<T> atomicAll(Filter... filters) {
                return new TAtomicOperation(ds, query(filters), true);
            }
        }
        if (collectionCache.contains(entityClass, ds())) {
            return collectionCache.get(entityClass, ds(), TMongoCollection.class);
        }
        return collectionCache.add(entityClass, ds(), new TMongoCollection(entityClass, ds()));
    }

    public <T> MongoCollection<T> collection(Class<T> entityClass) {
        class TAtomicOperation extends AtomicOperation<T> {
            public TAtomicOperation(Datastore ds, Query<T> query, boolean multiple) {
                super(ds, query, multiple);
            }
        }
        class TMongoCollection extends MongoCollection<T> {
            public TMongoCollection(Class<T> entityClass, Datastore ds) {
                super(entityClass, ds);
            }
            @Override
            public AtomicOperation<T> atomic(Filter... filters) {
                return new TAtomicOperation(ds, query(filters), false);
            }
            @Override
            public AtomicOperation<T> atomicAll(Filter... filters) {
                return new TAtomicOperation(ds, query(filters), true);
            }
        }
        if (collectionCache.contains(entityClass, ds())) {
            return collectionCache.get(entityClass, ds(), TMongoCollection.class);
        }
        return collectionCache.add(entityClass, ds(), new TMongoCollection(entityClass, ds()));
    }
