Firestore firebase Android search and update query











up vote
1
down vote

favorite












I am trying to update a field of existing document in my collection in FireBase Firestore. I want to search that document using one of its field.
My collection name is "complaints",
My document's structure looks like --



complainant_Name: "XYZ"
complaint_Details : "some random details"
e_Mail: "xyz@gmail.com"
id: 5
phone_No: "1234567890"


I want to search documents and if "id" field of a document is say 5, I want to update it say change "complainant_Name" field to "ABC". How to write the code for this query in java android? I couldn't find any code source which tells how to update after searching in Firebase Firestore.










share|improve this question






















  • I think, this will help you stackoverflow.com/questions/34537369/…
    – ATIK FAYSAL
    Nov 19 at 16:36










  • @ATIKFAYSAL You provided a link that explains how to do this in Firebase realtime database while the OP is asking for Cloud Firestore, which is a different product.
    – Alex Mamo
    Nov 19 at 16:43












  • I want to query on Firebase Firestore , not Firebase realtime database. The link you are providing is for the Firebase realtime database. And also I want to update as well (not only search as mentioned in link).
    – Ankit Selwal
    Nov 19 at 16:49















up vote
1
down vote

favorite












I am trying to update a field of existing document in my collection in FireBase Firestore. I want to search that document using one of its field.
My collection name is "complaints",
My document's structure looks like --



complainant_Name: "XYZ"
complaint_Details : "some random details"
e_Mail: "xyz@gmail.com"
id: 5
phone_No: "1234567890"


I want to search documents and if "id" field of a document is say 5, I want to update it say change "complainant_Name" field to "ABC". How to write the code for this query in java android? I couldn't find any code source which tells how to update after searching in Firebase Firestore.










share|improve this question






















  • I think, this will help you stackoverflow.com/questions/34537369/…
    – ATIK FAYSAL
    Nov 19 at 16:36










  • @ATIKFAYSAL You provided a link that explains how to do this in Firebase realtime database while the OP is asking for Cloud Firestore, which is a different product.
    – Alex Mamo
    Nov 19 at 16:43












  • I want to query on Firebase Firestore , not Firebase realtime database. The link you are providing is for the Firebase realtime database. And also I want to update as well (not only search as mentioned in link).
    – Ankit Selwal
    Nov 19 at 16:49













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am trying to update a field of existing document in my collection in FireBase Firestore. I want to search that document using one of its field.
My collection name is "complaints",
My document's structure looks like --



complainant_Name: "XYZ"
complaint_Details : "some random details"
e_Mail: "xyz@gmail.com"
id: 5
phone_No: "1234567890"


I want to search documents and if "id" field of a document is say 5, I want to update it say change "complainant_Name" field to "ABC". How to write the code for this query in java android? I couldn't find any code source which tells how to update after searching in Firebase Firestore.










share|improve this question













I am trying to update a field of existing document in my collection in FireBase Firestore. I want to search that document using one of its field.
My collection name is "complaints",
My document's structure looks like --



complainant_Name: "XYZ"
complaint_Details : "some random details"
e_Mail: "xyz@gmail.com"
id: 5
phone_No: "1234567890"


I want to search documents and if "id" field of a document is say 5, I want to update it say change "complainant_Name" field to "ABC". How to write the code for this query in java android? I couldn't find any code source which tells how to update after searching in Firebase Firestore.







android firebase google-cloud-firestore






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 16:25









Ankit Selwal

82




82












  • I think, this will help you stackoverflow.com/questions/34537369/…
    – ATIK FAYSAL
    Nov 19 at 16:36










  • @ATIKFAYSAL You provided a link that explains how to do this in Firebase realtime database while the OP is asking for Cloud Firestore, which is a different product.
    – Alex Mamo
    Nov 19 at 16:43












  • I want to query on Firebase Firestore , not Firebase realtime database. The link you are providing is for the Firebase realtime database. And also I want to update as well (not only search as mentioned in link).
    – Ankit Selwal
    Nov 19 at 16:49


















  • I think, this will help you stackoverflow.com/questions/34537369/…
    – ATIK FAYSAL
    Nov 19 at 16:36










  • @ATIKFAYSAL You provided a link that explains how to do this in Firebase realtime database while the OP is asking for Cloud Firestore, which is a different product.
    – Alex Mamo
    Nov 19 at 16:43












  • I want to query on Firebase Firestore , not Firebase realtime database. The link you are providing is for the Firebase realtime database. And also I want to update as well (not only search as mentioned in link).
    – Ankit Selwal
    Nov 19 at 16:49
















I think, this will help you stackoverflow.com/questions/34537369/…
– ATIK FAYSAL
Nov 19 at 16:36




I think, this will help you stackoverflow.com/questions/34537369/…
– ATIK FAYSAL
Nov 19 at 16:36












@ATIKFAYSAL You provided a link that explains how to do this in Firebase realtime database while the OP is asking for Cloud Firestore, which is a different product.
– Alex Mamo
Nov 19 at 16:43






@ATIKFAYSAL You provided a link that explains how to do this in Firebase realtime database while the OP is asking for Cloud Firestore, which is a different product.
– Alex Mamo
Nov 19 at 16:43














I want to query on Firebase Firestore , not Firebase realtime database. The link you are providing is for the Firebase realtime database. And also I want to update as well (not only search as mentioned in link).
– Ankit Selwal
Nov 19 at 16:49




I want to query on Firebase Firestore , not Firebase realtime database. The link you are providing is for the Firebase realtime database. And also I want to update as well (not only search as mentioned in link).
– Ankit Selwal
Nov 19 at 16:49












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










To solve this, please use the following lines of code:



FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference complaintsRef = rootRef.coolection("complaints");
complaintsRef.whereEqualTo("id", 5).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Map<Object, String> map = new HashMap<>();
map.put("complainant_Name", "ABC");
complaintsRef.document(document.getId()).set(map, SetOptions.merge());
}
}
}
});


After using this code, the property complainant_Name will hold the value of ABC.






share|improve this answer





















  • Thank you very much !!
    – Ankit Selwal
    Nov 19 at 17:02











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378868%2ffirestore-firebase-android-search-and-update-query%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










To solve this, please use the following lines of code:



FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference complaintsRef = rootRef.coolection("complaints");
complaintsRef.whereEqualTo("id", 5).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Map<Object, String> map = new HashMap<>();
map.put("complainant_Name", "ABC");
complaintsRef.document(document.getId()).set(map, SetOptions.merge());
}
}
}
});


After using this code, the property complainant_Name will hold the value of ABC.






share|improve this answer





















  • Thank you very much !!
    – Ankit Selwal
    Nov 19 at 17:02















up vote
1
down vote



accepted










To solve this, please use the following lines of code:



FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference complaintsRef = rootRef.coolection("complaints");
complaintsRef.whereEqualTo("id", 5).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Map<Object, String> map = new HashMap<>();
map.put("complainant_Name", "ABC");
complaintsRef.document(document.getId()).set(map, SetOptions.merge());
}
}
}
});


After using this code, the property complainant_Name will hold the value of ABC.






share|improve this answer





















  • Thank you very much !!
    – Ankit Selwal
    Nov 19 at 17:02













up vote
1
down vote



accepted







up vote
1
down vote



accepted






To solve this, please use the following lines of code:



FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference complaintsRef = rootRef.coolection("complaints");
complaintsRef.whereEqualTo("id", 5).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Map<Object, String> map = new HashMap<>();
map.put("complainant_Name", "ABC");
complaintsRef.document(document.getId()).set(map, SetOptions.merge());
}
}
}
});


After using this code, the property complainant_Name will hold the value of ABC.






share|improve this answer












To solve this, please use the following lines of code:



FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference complaintsRef = rootRef.coolection("complaints");
complaintsRef.whereEqualTo("id", 5).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Map<Object, String> map = new HashMap<>();
map.put("complainant_Name", "ABC");
complaintsRef.document(document.getId()).set(map, SetOptions.merge());
}
}
}
});


After using this code, the property complainant_Name will hold the value of ABC.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 16:42









Alex Mamo

37.9k62557




37.9k62557












  • Thank you very much !!
    – Ankit Selwal
    Nov 19 at 17:02


















  • Thank you very much !!
    – Ankit Selwal
    Nov 19 at 17:02
















Thank you very much !!
– Ankit Selwal
Nov 19 at 17:02




Thank you very much !!
– Ankit Selwal
Nov 19 at 17:02


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378868%2ffirestore-firebase-android-search-and-update-query%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin