Firestore - batch.add is not a function

前端 未结 6 1140
滥情空心
滥情空心 2020-12-24 10:31

The documentation for Firestore batch writes lists only set(), update() and delete() as permitted operations.

Is there no way

6条回答
  •  星月不相逢
    2020-12-24 11:33

    You can do this in two steps:

    // Create a ref with auto-generated ID
    var newCityRef = db.collection('cities').doc();
    
    // ...
    
    // Add it in the batch
    batch.set(newCityRef, { name: 'New York City' });
    

    The .doc() method does not write anything to the network or disk, it just makes a reference with an auto-generated ID you can use later.

提交回复
热议问题