def METHOD_NAME(query):
    """Return a command parsed from the given mongo db query."""
    db, coll = None, None
    ns = getattr(query, "ns", None)
    if ns:
        # version < 3.1 stores the full namespace
        db, coll = _split_namespace(ns)
    else:
        # version >= 3.1 stores the db and coll separately
        coll = getattr(query, "coll", None)
        db = getattr(query, "db", None)
    # pymongo < 3.1 _Query does not have a name field, so default to 'query'
    cmd = Command(getattr(query, "name", "query"), db, coll)
    cmd.query = query.spec
    return cmd