如何在 Firebase 实时数据库中更新 2 个单独的节点
How to update 2 separate nodes in Firebase Realtime Database
我在使用 Firebase 进行交易时遇到问题。我想同时更新 2 个节点(模型和场景),但它永远不会更新我的数据库。
这是我的代码:
public static void Delete(DataContainers.Scene iScene)
{
DatabaseReference leaderBoardRef = FirebaseDatabase.DefaultInstance.RootReference;
leaderBoardRef.RunTransaction(mutableData =>
{
mutableData.Child("Scenes/" + iScene.id).Value = null;
foreach (var _model in iScene.models)
{
mutableData.Child("models/" + _model).Value = null;
}
return TransactionResult.Success(mutableData);
});
}
还有其他方法吗?
您可以使用 multi-path update 一次性删除所有数据:
private void deleteScene(DataContainers.Scene iScene) {
// Get root database reference
DatabaseReference mDatabase = FirebaseDatabase.DefaultInstance.RootReference;
// Initialize a new list of "path->value" pairs
Dictionary<string, Object> childUpdates = new Dictionary<string, Object>();
// Delete the given scene and all of its models
childUpdates["/Scenes/" + iScene.id] = null;
foreach (var _model in iScene.models)
{
childUpdates["/models/" + _model] = null;
}
mDatabase.UpdateChildrenAsync(childUpdates);
}
我在使用 Firebase 进行交易时遇到问题。我想同时更新 2 个节点(模型和场景),但它永远不会更新我的数据库。
这是我的代码:
public static void Delete(DataContainers.Scene iScene)
{
DatabaseReference leaderBoardRef = FirebaseDatabase.DefaultInstance.RootReference;
leaderBoardRef.RunTransaction(mutableData =>
{
mutableData.Child("Scenes/" + iScene.id).Value = null;
foreach (var _model in iScene.models)
{
mutableData.Child("models/" + _model).Value = null;
}
return TransactionResult.Success(mutableData);
});
}
还有其他方法吗?
您可以使用 multi-path update 一次性删除所有数据:
private void deleteScene(DataContainers.Scene iScene) {
// Get root database reference
DatabaseReference mDatabase = FirebaseDatabase.DefaultInstance.RootReference;
// Initialize a new list of "path->value" pairs
Dictionary<string, Object> childUpdates = new Dictionary<string, Object>();
// Delete the given scene and all of its models
childUpdates["/Scenes/" + iScene.id] = null;
foreach (var _model in iScene.models)
{
childUpdates["/models/" + _model] = null;
}
mDatabase.UpdateChildrenAsync(childUpdates);
}