如何从Firestore中获取特定数据并在Objective-C中进行更新
我必须从Firestore获取我的用户,然后我想更新我的图像,它是字符串。我被困在一个地方 这是我的密码:如何从Firestore中获取特定数据并在Objective-C中进行更新,objective-c,google-cloud-firestore,Objective C,Google Cloud Firestore,我必须从Firestore获取我的用户,然后我想更新我的图像,它是字符串。我被困在一个地方 这是我的密码: FIRFirestore *defaultFirestore = [FIRFirestore firestore]; FIRCollectionReference *colRef = [defaultFirestore collectionWithPath:@"users"]; // to fetch my user profile [colRef queryWhereField:@"n
FIRFirestore *defaultFirestore = [FIRFirestore firestore];
FIRCollectionReference *colRef = [defaultFirestore collectionWithPath:@"users"]; // to fetch my user profile
[colRef queryWhereField:@"name" isEqualTo:currentUser.name];
[colRef getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) {
if (error != nil) {
NSLog(@"Error getting documents: %@", error);
} else {
for (FIRDocumentSnapshot *document in snapshot.documents) {
NSLog(@"%@", document.data); // my profile and after that I want to update the image
// here I want to update the user image how can I do it ??
}
}
}];
试试这个:
FIRFirestore *defaultFirestore = [FIRFirestore firestore];
FIRCollectionReference *colRef = [defaultFirestore collectionWithPath:@"users"];
FIRQuery *query = [colRef queryWhereField:@"name" isEqualTo:@"SIDDHANT Nigam"];
[query getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) {
if (error != nil) {
NSLog(@"Error getting documents: %@", error);
} else {
FIRDocumentSnapshot *document = snapshot.documents.firstObject;
[document.reference updateData:@{
@"imageurl": @""
}];
}
}];
}