【问题标题】:Does firestore have an equivalent updateChildren() functionfirestore 是否有等效的 updateChildren() 函数
【发布时间】:2017-11-01 21:14:32
【问题描述】:

来自 Firebase 实时数据库,我想知道 Cloud Firestore 是否具有与 updateChildren() 功能等效的功能。它可以同时批量更新多个节点,如果失败则不更新。

【问题讨论】:

    标签: firebase-realtime-database google-cloud-firestore batch-updates


    【解决方案1】:

    Firestore 支持可以将多个文档作为一个单元更新的事务,如果任何更新失败,则不支持:

    https://cloud.google.com/firestore/docs/manage-data/transactions

    这是来自所引用页面的 sn-p:

    // Get a new write batch
    var batch = db.batch();
    
    // Set the value of 'NYC'
    var nycRef = db.collection("cities").doc("NYC");
    batch.set(nycRef, {name: "New York City"});
    
    // Update the population of 'SF'
    var sfRef = db.collection("cities").doc("SF");
    batch.update(sfRef, {"population": 1000000});
    
    // Delete the city 'LA'
    var laRef = db.collection("cities").doc("LA");
    batch.delete(laRef);
    
    // Commit the batch
    batch.commit().then(function () {
        // ...
    });
    

    【讨论】:

    • 谢谢,这就是我需要的,但有一件事是“即使用户的设备离线,您也可以执行批量写入”,有没有办法禁用它,所以如果设备离线,批量写入会失败?我看到“客户端离线时事务将失败”。我有 10 种不同的写入(无读取),必须作为批处理完成。 Firebase 实时数据库有 keepSynced(true) 也许 Cloud Firestore 有类似的东西
    猜你喜欢
    • 1970-01-01
    • 2020-03-10
    • 2019-09-29
    • 1970-01-01
    • 2018-04-09
    • 2012-04-01
    • 2012-06-05
    • 2021-01-20
    • 1970-01-01
    相关资源
    最近更新 更多