'Converts a record from version 6 to version 7. Version 7 creates a
structured output for mongodb-databases script.'

@staticmethod
def migrate_schema_hosts_6_7(doc):

    assert (doc['schema_version'] == 6)
    update = {'$set': {'schema_version': 7}}
    updated = False
    for port in doc.get('ports', []):
        for script in port.get('scripts', []):
            if (script['id'] == 'mongodb-databases'):
                if ('mongodb-databases' not in script):
                    data = xmlnmap.add_mongodb_databases_data(script)
                    if (data is not None):
                        script['mongodb-databases'] = data
                        updated = True
    if updated:
        update['$set']['ports'] = doc['ports']
    return update
