【问题标题】:How to update 2 separate nodes in Firebase Realtime Database如何更新 Firebase 实时数据库中的 2 个独立节点
【发布时间】:2019-12-13 13:25:16
【问题描述】:

我在使用 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);
        });
    }

还有其他方法可以吗?

【问题讨论】:

    标签: c# firebase unity3d firebase-realtime-database transactions


    【解决方案1】:

    您可以根据需要使用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);
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      • 2021-12-06
      • 1970-01-01
      • 2019-10-11
      • 1970-01-01
      相关资源
      最近更新 更多