0

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);
Nate
  • 1,875
  • 15
  • 27
  • @noa I understand how to fetch just one entry with `findOneWithPredicate:predicate`, however is there any way just to do a collection.find() so that it returns all of the items under the collection? I have looked through ObjCMongodb's functionality's and nothing caught my eye that was able to do such a thing. – Nate Dec 18 '13 at 21:06
  • 1
    Yes, it's `-findAllWithError:`. – paulmelnikow Dec 18 '13 at 21:53
  • @noa tried using this (updated code above) – Nate Dec 18 '13 at 22:08

1 Answers1

1

-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);
}
paulmelnikow
  • 16,895
  • 8
  • 63
  • 114