                 }
                 
                 let documents = resultDocs.first?["cursor", "nextBatch"] as Document? ?? []
-                for (_, value) in documents {
+                for value in documents.arrayValue {
                     if let doc = transform(value.documentValue ?? [:]) {
                         self.data.append(doc)
                     }

import BSON

/// A Cursor is a pointer to a sequence/collection of Documents on the MongoDB server.
/// 
/// It can be looped over using a `for let document in cursor` loop like any other sequence.
///
/// It can be transformed into an array with `Array(cursor)` and allows transformation to another type.

    
    // documents already received by the server
    fileprivate var data: [T]
    
    fileprivate var position = 0
    
    /// A closure that transforms a document to another type if possible, otherwise `nil`
    typealias Transformer = (Document) -> (T?)
