def mongo_dt(dt):
    """Format a Python datetime the same as MongoDB would log it."""
    # strftime prints microseconds but MongoDB prints millis; strip 3 digits.
    return (f"{dt.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3]}"
            f"{dt.strftime('%z')}")