Firestore firebase Android search and update query
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.


add a comment |
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.


I think, this will help you stackoverflow.com/questions/34537369/…
– ATIK FAYSAL
Nov 19 '18 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 '18 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 '18 at 16:49
add a comment |
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.


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.




asked Nov 19 '18 at 16:25
Ankit Selwal
32
32
I think, this will help you stackoverflow.com/questions/34537369/…
– ATIK FAYSAL
Nov 19 '18 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 '18 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 '18 at 16:49
add a comment |
I think, this will help you stackoverflow.com/questions/34537369/…
– ATIK FAYSAL
Nov 19 '18 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 '18 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 '18 at 16:49
I think, this will help you stackoverflow.com/questions/34537369/…
– ATIK FAYSAL
Nov 19 '18 at 16:36
I think, this will help you stackoverflow.com/questions/34537369/…
– ATIK FAYSAL
Nov 19 '18 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 '18 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 '18 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 '18 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 '18 at 16:49
add a comment |
1 Answer
1
active
oldest
votes
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
.
Thank you very much !!
– Ankit Selwal
Nov 19 '18 at 17:02
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
.
Thank you very much !!
– Ankit Selwal
Nov 19 '18 at 17:02
add a comment |
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
.
Thank you very much !!
– Ankit Selwal
Nov 19 '18 at 17:02
add a comment |
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
.
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
.
answered Nov 19 '18 at 16:42


Alex Mamo
39.3k72759
39.3k72759
Thank you very much !!
– Ankit Selwal
Nov 19 '18 at 17:02
add a comment |
Thank you very much !!
– Ankit Selwal
Nov 19 '18 at 17:02
Thank you very much !!
– Ankit Selwal
Nov 19 '18 at 17:02
Thank you very much !!
– Ankit Selwal
Nov 19 '18 at 17:02
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
I think, this will help you stackoverflow.com/questions/34537369/…
– ATIK FAYSAL
Nov 19 '18 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 '18 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 '18 at 16:49