用户提交注册信息后,使用 watch
方法成功监听到数据已提交。然而,当我在数据提交后立即进行查询时,却无法获取到刚刚提交的数据。
补充:如果新建数据后,刷新小程序,调用同一个查询函数,会获取到数据。
app.router("SignUp", async (ctx, next) => {
const { nickName, documentType, nationality } = event.value;
const collections = [
{
name: "Users",
data: {
nickName,
nationality,
open_id: wxContext.OPENID,
status: status.PENDING_REDRIVE,
},
},
{
name: "CertData",
data: {
documentType,
},
},
];
try {
const result = await db.runTransaction(async (transaction) => {
const uploadPromises = collections.map(async (collection) => {
const params = {
unionid_id: wxContext.UNIONID,
createAt,
...collection.data,
};
const { _id } = await transaction.collection(collection.name).add({ data: params });
return { _id, type: collection.name };
});
return Promise.all(uploadPromises);
});
ctx.body = { data: result };
} catch (error) {
console.error("Transaction error: ", error);
ctx.body = { error: error.message };
}
});
可以提供一下最小可复现代码,问题里只有云函数的事务代码