用户提交注册信息后,使用 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 };
}
});
延迟查询是能查询得到?