首页 > 解决方案 > Firestore 不更新嵌入式集合中的值

问题描述

这是父节点 父结构

在里面我有客户

在此处输入图像描述

我正在尝试更新第一个客户的姓氏。 在此处输入图像描述

我有正确的身份证,我检查了很多次。我正在使用JAVA,代码如下:

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()是 firestore 的一个实例,我能够执行所有其他操作。

标签: javagoogle-cloud-firestoredatastore

解决方案


这是有效的:

    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);
    }

我认为这条线做到了,但我不确定我为什么需要它:

update.get().getUpdateTime()


推荐阅读