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.
android firebase google-cloud-firestore
add a comment |
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.
android firebase google-cloud-firestore
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
add a comment |
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.
android firebase google-cloud-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.
android firebase google-cloud-firestore
android firebase google-cloud-firestore
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
add a comment |
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
add a comment |
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
.
Thank you very much !!
– Ankit Selwal
Nov 19 at 17:02
add a comment |
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
.
Thank you very much !!
– Ankit Selwal
Nov 19 at 17:02
add a comment |
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
.
Thank you very much !!
– Ankit Selwal
Nov 19 at 17:02
add a comment |
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
.
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 at 16:42
Alex Mamo
37.9k62557
37.9k62557
Thank you very much !!
– Ankit Selwal
Nov 19 at 17:02
add a comment |
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
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 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