'Like `.insert_or_update()`, but `specs` parameter has to be an
iterable of (timestamp, spec) values. This will perform bulk
MongoDB inserts with the major drawback that the `getinfos`
parameter will be called (if it is not `None`) for each spec,
even when the spec already exists in the database and the call
was hence unnecessary.
It\'s up to you to decide whether having bulk insert is worth
it or if you want to go with the regular `.insert_or_update()`
method.'

def insert_or_update_bulk(self, specs, getinfos=None):

    bulk = self.db[self.colname_passive].initialize_unordered_bulk_op()
    count = 0
    try:
        for (timestamp, spec) in specs:
            if (spec is not None):
                updatespec = {'$inc': {'count': 1}, '$min': {'firstseen': timestamp}, '$max': {'lastseen': timestamp}}
                if (getinfos is not None):
                    infos = getinfos(spec)
                    if infos:
                        updatespec['$setOnInsert'] = infos
                bulk.find(spec).upsert().update(updatespec)
                count += 1
                if (count >= config.BULK_UPSERTS_MAXSIZE):
                    utils.LOGGER.debug('DB:MongoDB    bulk    upsert:    %d', count)
                    bulk.execute()
                    bulk = self.db[self.colname_passive].initialize_unordered_bulk_op()
                    count = 0
    except IOError:
        pass
    if (count > 0):
        utils.LOGGER.debug('DB:MongoDB    bulk    upsert:    %d    (final)', count)
        bulk.execute()
