                 throw MongoKittenError(.protocolParsingError, reason: nil)
             }
             
-            array.append(Document(bytes: bytes))
-        }
-        
-        self = array
+            append(Document(bytes: bytes))
+        }
+    }
+    
+    init(buffer: inout ByteBuffer, consumeBytes: Int) throws {
+        self = []
+        
+        var consumedBytes = 0
+        while consumedBytes < consumeBytes {
+            let documentSize = try buffer.getInteger(
+                at: buffer.readerIndex,
+                endianness: .little,
+                as: Int32.self
+                ).assert()
+            
+            consumedBytes += Int(documentSize)
+            
+            guard let bytes = buffer.readBytes(length: numericCast(documentSize)) else {
+                throw MongoKittenError(.protocolParsingError, reason: nil)
+            }
+            
+            append(Document(bytes: bytes))
+        }
     }
 }
 


extension Array where Element == Document {
    init(buffer: inout ByteBuffer, count: Int) throws {
        var array = [Document]()
        array.reserveCapacity(count)
        
        for _ in 0..<count {
            let documentSize = try buffer.getInteger(

            switch kind {
            case 0: // body
                documents += try [Document](buffer: &buffer, count: 1)
            case 1: // document sequence
                let size = try buffer.assertLittleEndian() as Int32
                let documentSequenceIdentifier = try buffer.readCString() // Document sequence identifier
                // TODO: Handle document sequence identifier correctly
                
                let bsonObjectsSectionSize = Int(size) - 4 - documentSequenceIdentifier.utf8.count - 1
                guard bsonObjectsSectionSize > 0 else {
                    throw MongoKittenError(.protocolParsingError, reason: .unexpectedValue)
                }
                
                documents += try [Document](buffer: &buffer, consumeBytes: bsonObjectsSectionSize)
            default:
                throw MongoKittenError(.protocolParsingError, reason: .unexpectedValue)
            }
        }
        
        if flags.contains(.checksumPresent) {
            // Checksum validation is unimplemented
            // MongoDB 3.6 does not support validating the message checksum, but will correctly skip it if present.
            buffer.moveReaderIndex(forwardBy: 4)
        }
        
        return ServerReply(responseTo: responseTo, cursorId: 0, documents: documents)
