I am creating a following system with Firestore using the following schema:
--- following (collection)
| |
| --- uid (document)
| |
| --- userFollowing (collection)
| |
| --- uid (documents)
| |
| --- uid (documents)
But I can't put the documents (the user ids) in the collection. This code:
Map<String, Object> following = new HashMap<>();
following.put("title", uid);
mDocRef = fsRef.collection("following").document(fAuth.getCurrentUser().getUid()).collection("userFollowing").document(uid);
mDocRef.set(following).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
followornot.setText("Segui giá");
followornot.setBackgroundColor(Color.argb(255,198, 198, 198));
followornotBool = true;
}
});
produces this result in the Firestore:
if I try with:
mDocRef = fsRef.collection("following").document(fAuth.getCurrentUser().getUid()).collection("userFollowing");
mDocRef.set(following).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
followornot.setText("Segui giá");
followornot.setBackgroundColor(Color.argb(255,198, 198, 198));
followornotBool = true;
}
});
It will give me the following error:
Required type: DocumentReference
Provided: CollectionReference
so I can't do it
Is there a way to get the data structure I wrote at the beginning of the post?