Yusuf Aydın
Yusuf Aydın

Reputation: 27

add data in same field to firebase

I'm trying to add users who applying for the job and I wanna storage this users in same field but my code deletes previous user so how can I I can add it without deleting previous user here is my code

String email=user.getEmail();
HashMap<String,Object> basvurubilgileri=new HashMap<>();
basvurubilgileri.put("İlana Başvuran Kişiler",email);
firestore.collection("İlanlar").document(ilanbaslıgı).update(basvurubilgileri).addOnSuccessListener(new OnSuccessListener<Void>() {
    @Override
    public void onSuccess(Void unused) {
        Toast.makeText(Basvurma.this, "Başvurunuz Başarılı Bir Şekilde Yapılmıştır", Toast.LENGTH_SHORT).show();
        Intent intent=new Intent(Basvurma.this,Secimekrani.class);
        startActivity(intent);
        finish();
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull  Exception e) {
        Toast.makeText(Basvurma.this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
    }
});

Upvotes: 0

Views: 54

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599081

It sounds like you want İlana Başvuran Kişiler to be an array field. To add a value to an array field, you can use array-union

basvurubilgileri.put("İlana Başvuran Kişiler",FieldValue.arrayUnion(email));

The rest of your could stays the same with this.

Upvotes: 2

Related Questions