def _project(doc, projection):
    """Return new doc with items filtered according to projection."""
    def _include_key(key, projection):
        for k, v in projection.items():
            if key == k:
                if v == 0:
                    return False
                elif v == 1:
                    return True
                else:
                    raise ValueError('Projection value must be 0 or 1.')
        if projection and key != '_id':
            return False
        return True
    return {k: v for k, v in doc.items() if _include_key(k, projection)}