예제 #1
0
def get_record_field_by_field_value(gc_collection: collection.Collection, res_field: str, fields: List,
                                    fields_values: List, is_field_array: List):
    """
    Returns the given res_field of all the records in the given collection where the field with
    the given name is one of the given field_values.

    :param gc_collection: The collection to be queried
    :param res_field: The desired field to be returned
    :param fields: List of field to match by.
    :param fields_values: List of Lists of desired values dor each field.
    :param is_field_array: List of Booleans indicating whether the field is an array or not.
    :return: List of ids in which the field is one of the given values
    """

    query = {}

    for field_num in range(len(fields)):
        # ToDo: replace the is_field_array parameter with type checking of passed field_values
        if is_field_array[field_num]:
            query[fields[field_num]] = {"$in": fields_values[field_num]}
        else:
            query[fields[field_num]] = fields_values[field_num]

    # query["is_on"] = True # uncomment if querying orchestration_vm

    return gc_collection.distinct(res_field, query)