为什么updateChildValues会覆盖而不是更新Firebase中的数据?

时间:2018-03-05 22:19:31

标签: firebase firebase-realtime-database

我正在尝试使用.updateChildValues方法更新Firebase数据库中的节点,但它会覆盖整个节点,而不是使用新值更新它。有谁为什么会这样?

func writeToDB() {
   let path = "FeesCleaner/\(self.fromUidString.text!)"
    let childUpdates = [path:  self.feesCleaner_Object] as [String : Any]
        self.dbRef.updateChildValues(childUpdates, withCompletionBlock: { (error, response) in
        })
 }

//self.feesCleaner_Object is shown below in JSON format.

"FeesCleaner" : {
  "05MSPgkP1ddhFqXDRjIB4npGEPV2" : {
    "BackgroundCheck" : {
      "FeeAmount" : "30",
      "FeeStatus" : "false",
      "TimeStampProfileCreated" : "2992939382"
   },
    "OutstandingFees" : {
      "BalanceCarriedForwardAmount" : "0.0",
      "PreviousBalanceCarriedForward" : "0.0",
      "TimeStampFeesCarriedForward" : "1520287823"
   },
   "TimeStampFeesSaved" : {
     "1520287823" : {
       "BalanceCarriedForwardAmount" : "0.0",
       "PayPeriodTimeStampStartDate" : "1510531260",
       "PaymentRef" : "354576819",
       "PreviousBalanceCarriedForward" : "0.0",
       "TimeStampDisbursedPayment" : "1520287823",
       "TotalAmountDebtToCleaner" : "0.0",
       "TotalAmountFeesCurrentPayPeriod" : "0.0",
       "TotalAmountPaidToCleanerForAllBookings" : "0.0",
       "TotalAmountProfitToCleanerForAllBookings" : "0.0"
     }
   }
  }
},

1 个答案:

答案 0 :(得分:1)

给定单个键路径,updateChildValues仅更新第一个子级别的数据,并且超出第一个子级别传递的任何数据都被视为setValue操作。多路径行为允许使用更长的路径而不覆盖数据。请查看示例和相关文档:https://www.firebase.com/docs/ios/guide/saving-data.html#section-update