Question

I can retrieve a single entry from a collection in a mongodb but I cannot retrieve the entire collection. After I retrieve the entire collection I would like to put it into a dictionary. Retrieving the entire collection should be simple. I have tested the various commands I would use in the shell to accomplish the task, but all are unsuccessful once translated into objective-c.

   //Message Retrieval
    BSONDocument *resultDoc = [collection findAllWithError:&error];
    NSDictionary *result = [BSONDecoder decodeDictionaryWithDocument:resultDoc];
    NSLog(@"fetch result: %@", result);
Was it helpful?

Solution

-findAllWithError: returns an array of documents:

NSArray *results = [collection findAllWithError:&error];
for (BSONDocument *resultDoc in results) {
    NSDictionary *result = [BSONDecoder decodeDictionaryWithDocument:resultDoc];
    NSLog(@"fetch result: %@", result);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top