문제

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);
도움이 되었습니까?

해결책

-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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top