Above is the structure of collection "networks". What is want to do is add another element in "users" field. It's a HashMap
. I want to achieve is Key= xyz@gmail.com and its values {displayName: "Anirudh Kumar", "role":"admin"}.
xyz@gmail.com displayName: "Anirudh Kumar" role: "admin"
I have tried few things but it doesn't seems to work.
1st option
Map<String, Network.NetworkUser> users = new HashMap<>();
users.put(email, networkUser);
db.collection("networks").document("id")
.update("users",FieldValue.arrayUnion(users));
2nd option
db.collection("networks").document(userNetwork.getNetworkUid())
.set(users,SetOptions.merge());
3rd option
db.collection("networks").document(userNetwork.getNetworkUid())
.update("users."+email,networkUser);
3rd option takes me closer to answer, but because of dot [.] in an email it creates another row, let me know if somehow this can be avoided.
If anyone can assist me how can I achieve the desired goal, it would be appreciated. Thanks.