2013-12-17 70 views
0

我可以從MongoDB中的集合中檢索單個條目,但我無法檢索整個集合。在我檢索完整集合後,我想將其放入字典中。檢索整個集合應該很簡單。我測試了我在shell中用來完成任務的各種命令,但是一旦轉換爲objective-c,所有命令都不成功。檢索整個集合,然後將其添加到字典

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

@noa我瞭解如何獲取和'findOneWithPredicate只有一個條目:predicate',但是有什麼辦法只是做一個collection.find( ),以便它返回集合下的所有項目?我已經瀏覽了ObjCMongodb的功能,並沒有引起我的注意,它能夠做到這一點。 – Nate

+1

是的,它是'-findAllWithError:'。 – paulmelnikow

+0

@noa嘗試使用此(上述更新代碼) – Nate

回答

1

-findAllWithError:返回文檔的數組:

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

非常感謝您的幫助和快速響應 – Nate

相關問題