def spec_str(spec):
    """
    Change a spec to the json object format used in mongo.
    eg. Print dict in python gives: {'a':'b'}
        mongo shell would do {a:'b'}
        Mongo shell can handle both formats but it looks more like the
        official docs to keep to their standard.
    :param spec: Dictionary. A mongo spec.
    :return: String. The spec as it is represended in the mongodb shell examples.
    """

    if spec is None:
        return "{}"
    if isinstance(spec, list):
        out_str = "[" + ', '.join([spec_str(x) for x in spec]) + "]"
    elif isinstance(spec, dict):
        out_str = "{" + ', '.join(["{}:{}".format(x, spec_str(spec[x])
                                                  ) for x in sorted(spec)]) + "}"
    elif spec and isinstance(spec, str) and not spec.isdigit():
        out_str = "'" + spec + "'"
    else:
        out_str = spec

    return out_str