如何从firebase读取ONCE(不更新)

问题描述 投票:-2回答:1

我有一个应用程序,它应首先从firebase数据库中读取一个子项,然后将其子项的键存储在一个数组中。之后我编写了函数来将新值写入我在firebase中读取的同一个孩子。

我希望read函数只读取一次,而不是像现在那样更新自己。我想得到的第一个值不是writeFunction写的。

EX:在我的火力基地:电影{242:“Jumanji:欢迎来到丛林”342:“Thor:Ragnarok”}

在我的代码:

    func readOldMovieID(){
       ref = Database.database().reference()
    let userID = Auth.auth().currentUser?.uid
    ref?.child("users").child(userID!).child("Movie").observeSingleEvent(of: .childAdded, with: { (snapshot) in
         print("read Key:")
            print(snapshot.key)
                self.lastMovie.append(snapshot.key)

    }) { (error) in
        print(error.localizedDescription)
    }

我试过不同的代码让这个函数读一个!但我认为我仍然无法找到合适的人选。

ios swift firebase firebase-realtime-database
1个回答
0
投票

在阅读之前检查孩子是否存在解决问题。谢谢大家

© www.soinside.com 2019 - 2024. All rights reserved.