(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts)
Get an **insert** message.
Get an **insert** message.
Get an ** insert ** message .
def insert(collection_name, docs, check_keys,
           safe, last_error_args, continue_on_error, opts):
    """Get an **insert** message."""
    options = 0
    if continue_on_error:
        options += 1
    data = struct.pack("<i", options)
    data += bson._make_c_string(collection_name)
    encoded = [bson.BSON.encode(doc, check_keys, opts) for doc in docs]
    if not encoded:
        raise InvalidOperation("cannot do an empty bulk insert")
    max_bson_size = max(map(len, encoded))
    data += _EMPTY.join(encoded)
    if safe:
        (_, insert_message) = __pack_message(2002, data)
        (request_id, error_message, _) = __last_error(collection_name,
                                                      last_error_args)
        return (request_id, insert_message + error_message, max_bson_size)
    else:
        (request_id, insert_message) = __pack_message(2002, data)
        return (request_id, insert_message, max_bson_size)
def insert ( collection_name , docs , check_keys , safe , last_error_args , continue_on_error , opts ) : options = 0 if continue_on_error : options += 1 data = struct . pack ( "<i" , options ) data += bson . _make_c_string ( collection_name ) encoded = [ bson . BSON . encode ( doc , check_keys , opts ) for doc in docs ] if not encoded : raise InvalidOperation ( "cannot do an empty bulk insert" ) max_bson_size = max ( map ( len , encoded ) ) data += _EMPTY . join ( encoded ) if safe : ( _ , insert_message ) = __pack_message ( 2002 , data ) ( request_id , error_message , _ ) = __last_error ( collection_name , last_error_args ) return ( request_id , insert_message + error_message , max_bson_size ) else : ( request_id , insert_message ) = __pack_message ( 2002 , data ) return ( request_id , insert_message , max_bson_size )