JohnStar
JohnStar

Reputation: 21

Firestore not updating values in embedded collections

Here is parent node parent structure

Inside I have clients

enter image description here

I'm trying to update the lastName of the first client. enter image description here

I have the correct ID's, I've checked multiple times. I'm using JAVA, here is the code:

public void updateClient(ClientDto client) {
    if(client.getUserId() == null){
        throw new IllegalArgumentException("userId cannot be null when" +
                " updating a client");
    }

    final ClientDto clientById = this.getClientById(client.getClientId(),client.getUserId());

    Map<String, Object> data = new HashMap<>();
    data.put("name", client.getName());
    data.put("lastName", client.getLastName());
    data.put("middleName", client.getMiddleName());
    data.put("email", client.getEmail());
    data.put("phone", client.getPhone());
    data.put("lastUpdatedBy", client.getLastUpdatedBy());
    data.put("lastUpdatedDate", client.getLastUpdatedDate());

    this.fireDao.getDb()
            .collection("users").document(client.getUserId())
            .collection("clients")
            .document(client.getClientId()).update(data);
}

this.fireDao.getDb() is an instance of firestore and I'm able to preform all other operations.

Upvotes: 0

Views: 55

Answers (1)

JohnStar
JohnStar

Reputation: 21

Here is what worked:

    final ApiFuture<WriteResult> update = this.fireDao.getDb().collection("users").document(client.getUserId())
            .collection("clients")
            .document(client.getClientId()).update(data);

    try {
        log.info(format(
                "Updating userId %s for customer id %s at time %s",
                client.getUserId(),
                client.getClientId(),
                update.get().getUpdateTime()));
    } catch (InterruptedException | ExecutionException e) {
        log.error(format(
                "Error updating userId %s for customer id %s",
                client.getUserId(),
                client.getClientId()), e);
    }

I think this line did it but I'm not sure why I need it:

update.get().getUpdateTime()

Upvotes: 1

Related Questions