def ensure_pymongo(obj):
    """If obj is wrapped by motor, return the internal pymongo object

    :param obj:
        a pymongo or motor client, database, or collection
    :returns:
        pymongo client, database, or collection
    """
    if obj.__class__.__module__.startswith("pymongo."):
        return obj
    if obj.delegate.__class__.__module__.startswith("pymongo."):
        return obj.delegate
    raise TypeError("Neither a pymongo nor a motor object")