'Insert an iterable of documents.
>>> db.test.count()
0
>>> result = db.test.insert_many([{\'x\': i} for i in range(2)])
>>> result.inserted_ids
[ObjectId(\'54f113fffba522406c9cc20e\'), ObjectId(\'54f113fffba522406c9cc20f\')]
>>> db.test.count()
2
:Parameters:
- `documents`: A iterable of documents to insert.
- `ordered` (optional): If ``True`` (the default) documents will be
inserted on the server serially, in the order provided. If an error
occurs all remaining inserts are aborted. If ``False``, documents
will be inserted on the server in arbitrary order, possibly in
parallel, and all document inserts will be attempted.
- `bypass_document_validation`: (optional) If ``True``, allows the
write to opt-out of document level validation. Default is
``False``.
:Returns:
An instance of :class:`~pymongo.results.InsertManyResult`.
.. seealso:: :ref:`writes-and-ids`
.. note:: `bypass_document_validation` requires server version
**>= 3.2**
.. versionchanged:: 3.2
Added bypass_document_validation support
.. versionadded:: 3.0'

def insert_many(self, documents, ordered=True, bypass_document_validation=False):

    if ((not isinstance(documents, collections.Iterable)) or (not documents)):
        raise TypeError('documents    must    be    a    non-empty    list')
    inserted_ids = []
    def gen():
        'A    generator    that    validates    documents    and    handles    _ids.'
        for document in documents:
            common.validate_is_document_type('document', document)
            if (not isinstance(document, RawBSONDocument)):
                if ('_id' not in document):
                    document['_id'] = ObjectId()
                inserted_ids.append(document['_id'])
            (yield (message._INSERT, document))
    blk = _Bulk(self, ordered, bypass_document_validation)
    blk.ops = [doc for doc in gen()]
    blk.execute(self.write_concern.document)
    return InsertManyResult(inserted_ids, self.write_concern.acknowledged)
