I am building an Android app to sell books. My users can post ads for their used books and sell them. I am planning to add a feature where my users can opt to go anonymous. There will be checkbox with name Make me anonymous
. If users check that box, their phone number and name will not be visible to others. Only a generic name should be visible.
Now the problem is, I want to put an entry anonymous = true
in every ad documents that the user uploaded.
I want to query the ads that the user put and add a field anonymous = true
. I want to do something like below:
final CheckBox anonymousCB = findViewById(R.id.anonymousCB);
anonymousCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (anonymousCB.isChecked()){
WriteBatch batch = firestore.batch();
DocumentReference sfRef = firestore.collection("books").whereEqualTo(uid,uid);
batch.update(sfRef, "anonymous", "true");
}
}
});
But I cannot make a query and insert a field into all the documents that match the query. Is there any better way to do this?