I am using the MongoKitten library to extract documents from mongoDB.
In my mongoDB there is the following document:
{
...
foo: ["A", "B"]
...
}
I can request db, but I cannot go through the array of fooreturned documents. For example, let's say that I save the results of my query to mongoDocs.
for Doc in mongoDocs {
print(Doc["foo"] as Any) // prints ["A", "B"]
var tempFoos = [String]()
for foo in Doc["foo"] { // gives error: Type 'Value' does not conform to protocol "Sequence"
print("Foo: " + foo)
tempFoos.append(foo)
}
}
I understand the error. Basically, my array foodoes not conform to the Sequence protocol, which allows me to iterate over it. But how can I fix this?
Change . This uses the code that I use to get mongoDocs. I printed the results and used other properties. I just can't repeat this array.
mongoDocs = try self.geographiesCollection!.find(matching: q, projecting: projection, limitedTo: 100)
MongoKitten. Cursor<Document>