public BasicDBList readPhotosFromActivity(int start, int length, String userId) {
        int end = start + length;
        int iterator = 0;
        Set<String> photoIdSet = new HashSet<String>();
        DBCursor cursor = database.getCollection(ACTIVITY_COLLECTION).find(new BasicDBObject("_id", Pattern.compile("^" + userId)), new BasicDBObject("photos", 1));
        try {
            while (cursor.hasNext()) {
                DBObject activity = cursor.next();
                if (activity.get("photos") != null) {
                    BasicDBList photos = (BasicDBList) activity.get("photos");
                    if ((iterator + photos.size()) < start) {
                        iterator += photos.size();
                        continue;
                    }
                    for (Object photoObject : photos) {
                        if (iterator < start) {
                            iterator++;
                            continue;
                        }
                        if (iterator > end) {
                            return readPhotos(photoIdSet);
                        }

                        if (!photoIdSet.contains(photoObject)) {
                            photoIdSet.add(photoObject.toString());
                            iterator++;
                        }
                    }
                }
            }
        } finally {
            cursor.close();
        }

        return readPhotos(photoIdSet);
    }