                     if input["_id"] == .nothing {
                         var output = input
                         output["_id"] = ~ObjectId()
-                        newDocuments.append(output)
+                        newIds.append(output["_id"])
                         return .document(output)
                     } else {
-                        newDocuments.append(input)
+                        newIds.append(input["_id"])
                         return .document(input)
                     }
                 })

    ///
    /// - throws: When we can't send the request/receive the response, you don't have sufficient permissions or an error occurred
    ///
    /// - returns: The documents with their (if applicable) updated ObjectIds
    @discardableResult
    public func insert(_ documents: [Document], stoppingOnError ordered: Bool? = nil, timeout customTimeout: TimeInterval? = nil) throws -> [Document] {
        let timeout: TimeInterval = customTimeout ?? (60 + (Double(documents.count) / 50))
        
        var documents = documents
        var newDocuments = [Document]()
        let protocolVersion = database.server.serverData?.maxWireVersion ?? 0
        
        while !documents.isEmpty {

    ///
    /// - throws: When we can't send the request/receive the response, you don't have sufficient permissions or an error occurred
    ///
    /// - returns: The inserted document's id
    @discardableResult
    public func insert(_ document: Document) throws -> Value {
        let result = try self.insert([document])
        
        guard let newId = result.first?["_id"] else {
            throw MongoError.insertFailure(documents: [document], error: nil)
        }
        
        return newId
    }
    
    /// TODO: Detect how many bytes are being sent. Max is 48000000 bytes or 48MB
