martijnwalraven / meteor-ios

Meteor iOS integrates native iOS apps with the Meteor platform (http://www.meteor.com) through DDP
MIT License
741 stars 82 forks source link

Not able to get the document ID from the collection. #111

Open saisrinivas25 opened 7 years ago

saisrinivas25 commented 7 years ago

Hi,

I am using subscription to get documents from the server. And then storing them in METCollection object. Code: METCollection collection = [client.database collectionWIthName:@"database"]; NSArray array = [collection allDocuments];

Now, I want to get the document ID of individual documents while looping through the array. I have gone through the source code, but I could not find anything that gives ID of the document.

Please tell me how to get the documentID from the document.

Thanks & Regards, Srinivas

martijnwalraven commented 7 years ago

METDocuments have a key property, which is an instance of METDocumentKey, which has a documentID property.

saisrinivas25 commented 7 years ago

I tried it earlier, but the xcode threw an error saying documentID is not a property of NSString. This time I tried it again with instantiating the key to a separate variable first and then got the documentID from it. Thank you so much. METDocumentKey docKey = [collection[i] key]; documentID = [docKey documentID];

brianscroggins24 commented 7 years ago

I did this to return the documentId. Ignore the sharedInstance. That's just me creating a singleton for easy use. the documentKeyFoObjectID is what's important return [[MeteorSession sharedInstance]documentKeyForObjectID:self.objectID].documentID;