检索整个集合,然后将其添加到字典中



我可以从mongodb中的集合中检索单个条目,但我无法检索整个集合。检索整个集合后,我想将其放入字典中。检索整个集合应该很简单。我已经测试了我在 shell 中用来完成任务的各种命令,但一旦翻译成 objective-c,所有命令都不成功。

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

-findAllWithError: 返回一个文档数组:

NSArray *results = [collection findAllWithError:&error];
for (BSONDocument *resultDoc in results) {
    NSDictionary *result = [BSONDecoder decodeDictionaryWithDocument:resultDoc];
    NSLog(@"fetch result: %@", result);
}

最新更新