import logging


def mergeDoc(existing_doc, new_doc):
    """ existing_doc is merged with new_doc. 
    
    Returns true/false if existing_doc is modified.
    """
    records = existing_doc.setdefault("records", [])   
    if 'records' not in new_doc:
        return False
    isModified = False
    for new_record in new_doc['records']:
        if new_record not in records:
            records.append(new_record)
            isModified = True
    logging.info("# merged records %d " % len(records))

    # Merge images.
    images = existing_doc.setdefault("images", [])   
    for new_image in new_doc['images']:
        if new_image not in images:
            images.append(new_image)
            isModified = True
    logging.info("# merged images %d " % len(images))

    # Merge sources.
    sources = existing_doc.setdefault("sources", [])   
    for new_source in new_doc['source']:
        if new_source not in sources:
            sources.append(new_source)
            isModified = True
    logging.info("# merged sources %d " % len(sources))

    return isModified