'Updates the first record matching "spec" (without
"firstseen", "lastseen" and "count") by mixing "firstseen",
"lastseen" and "count" from "spec" and from the database.
This is usefull to mix records from different databases.'

def insert_or_update_mix(self, spec, getinfos=None):

    updatespec = {}
    if ('firstseen' in spec):
        updatespec['$min'] = {'firstseen': spec['firstseen']}
        del spec['firstseen']
    if ('lastseen' in spec):
        updatespec['$max'] = {'lastseen': spec['lastseen']}
        del spec['lastseen']
    if ('count' in spec):
        updatespec['$inc'] = {'count': spec['count']}
        del spec['count']
    else:
        updatespec['$inc'] = {'count': spec['count']}
    if ('infos' in spec):
        updatespec['$setOnInsert'] = {'infos': spec['infos']}
        del spec['infos']
    if ('fullinfos' in spec):
        if ('$setOnInsert' in updatespec):
            updatespec['$setOnInsert'].update({'fullinfos': spec['fullinfos']})
        else:
            updatespec['$setOnInsert'] = {'fullinfos': spec['fullinfos']}
        del spec['fullinfos']
    current = self.get_one(spec, fields=[])
    if current:
        self.db[self.colname_passive].update({'_id': current['_id']}, updatespec)
    else:
        if ((getinfos is not None) and ('$setOnInsert' not in updatespec)):
            infos = getinfos(spec)
            if infos:
                updatespec['$setOnInsert'] = infos
        self.db[self.colname_passive].update(spec, updatespec, upsert=True)
