gpt4 book ai didi

java - 如何在 Firestore 中批量写入后获取更新的文档引用?

转载 作者:行者123 更新时间:2023-11-29 23:04:39 25 4
gpt4 key购买 nike

我有一个使用批量更新更新的文档,如何在提交后获取文档引用或数据。

DocumentReference d = db.collection("posts").document(p.getUserId()).collection("userPosts")
.document(p.getDocId());

batch.update(d,"commentCount", FieldValue.increment(1));



batch.commit().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful())
{
Log.d("post","Successfully batch writteen");
Intent resultIntent = new Intent();
resultIntent.putExtra("docId", p.docId);
//Need result document here
resultIntent.putExtra("commentCount", task.getResult());
setResult(RESULT_OK);
finish();
}
else
{
Log.d("post","Failed batch write");
finish();
}

}
});

最佳答案

根据您的评论:

i mean after commiting i need the values inside that Document

如果在批量写入结束后需要新的更新值,则需要对完全 相同的引用进行get() 调用。为了确保批写入完成,您应该从回调内部,从 onComplete() 方法内部获取该文档。

d.get().addOnCompleteListener(/* ... */);

关于java - 如何在 Firestore 中批量写入后获取更新的文档引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56685812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com