Android 不同集合上的FireStore批处理写入

Android 不同集合上的FireStore批处理写入,android,firebase,google-cloud-firestore,Android,Firebase,Google Cloud Firestore,是否有其他方法可以对属于不同集合的多个文档执行一组写入操作 有点像在多个文档上批量写入,就像在正式文档中一样 例如, WriteBatch batch = db.batch(); // Set the value of 'NYC' in 'cities' collection DocumentReference nycRef = db.collection("cities").document("NYC"); batch.set(nycRef, map1); // Set the va

是否有其他方法可以对属于不同集合的多个文档执行一组写入操作

有点像在多个文档上批量写入,就像在正式文档中一样

例如,

WriteBatch batch = db.batch();

// Set the value of 'NYC' in 'cities' collection

DocumentReference nycRef = db.collection("cities").document("NYC");
batch.set(nycRef, map1);


// Set the value of 'ABC' in 'SomeOtherCollection' collection

DocumentReference otherRef = db.collection("SomeOtherCollection").document("ABC");
batch.set(otherRef,map2));

可以对不同的集合执行批处理写入吗?

批处理操作可以跨集合工作。从:

//获取新的写入批处理
WriteBatch batch=db.batch();
//设置“NYC”的值
DocumentReference nycRef=db.集合(“城市”).文件(“纽约市”);
batch.set(nycRef,new City());
//更新“SF”的人口
文件参考sfRef=db.集合(“城市”).文件(“SF”);
批量更新(sfRef,“总体”,1000000毫升);
//删除城市“LA”
DocumentReference laRef=数据库集合(“城市”)。文档(“LA”);
批量删除(laRef);
//提交批处理
batch.commit().addOnCompleteListener(新的OnCompleteListener()){
@凌驾
未完成的公共void(@NonNull任务){
// ...
}
});

既然您传入了要写入的文档
batch.set()
,那么您也可以将不同集合中的文档传入每个调用。

只是想知道是否有可能,就像我在示例中所示。如果文档中有这样的示例,那就太好了,因为它没有明确说明。
// Get a new write batch
WriteBatch batch = db.batch();

// Set the value of 'NYC'
DocumentReference nycRef = db.collection("cities").document("NYC");
batch.set(nycRef, new City());

// Update the population of 'SF'
DocumentReference sfRef = db.collection("cities").document("SF");
batch.update(sfRef, "population", 1000000L);

// Delete the city 'LA'
DocumentReference laRef = db.collection("cities").document("LA");
batch.delete(laRef);

// Commit the batch
batch.commit().addOnCompleteListener(new OnCompleteListener<Void>() {
    @Override
    public void onComplete(@NonNull Task<Void> task) {
        // ...
    }
});