gpt4 book ai didi

java - 如何在 Firestore 数据库中运行多个事务?我面临的问题是

转载 作者:行者123 更新时间:2023-11-29 18:27:52 25 4
gpt4 key购买 nike

我正在尝试在 android 的 firestore 数据库中运行多个事务。但他们并不是同时工作。现在只有 DocumentReference PostRef 的事务在工作。

请协助运行多个事务。

db.runTransaction(new Transaction.Function<Void>() {
@Override
public Void apply(Transaction transaction) throws FirebaseFirestoreException {

DocumentSnapshot documentSnapshot1 = transaction.get(PostRef);
boolean l2 = documentSnapshot1.getBoolean("l2");
if(l2 == false) {
transaction.update(PostRef, "l2", true);
return null;

}

DocumentSnapshot documentSnapshot2 = transaction.get(PostUserRef);
long l11 = documentSnapshot2.getLong("l1");
{ transaction.update(PostRef, "l1", l11+1);

}


DocumentSnapshot snapshot = transaction.get(likesRef);
boolean l1 = snapshot.getBoolean("l1");
if (l1 == false) {

transaction.update(likesRef, "l1", true);
//2 transactions to update userprofile



return null;
} else
{
throw new FirebaseFirestoreException("You already liked",
FirebaseFirestoreException.Code.ABORTED);
}


}
})

最佳答案

我所做的是将多个事务设置为一个函数,然后在 onclick 事件中调用这些函数并执行所需的函数

关于java - 如何在 Firestore 数据库中运行多个事务?我面临的问题是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57935966/

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