Creating and appending arrays in Firebase-ios-swift

后端 未结 2 756
失恋的感觉
失恋的感觉 2021-01-24 07:26

How to create an array in the firebase 3.0 and perform the functions of append and delete in the array

This is the data structure i am looking for:-

1-Us         


        
2条回答
  •  無奈伤痛
    2021-01-24 07:31

    As the links provided by Ivan explain, arrays are seldom a good idea in a database where multiple users are concurrently adding/changing the data. There also seems to be no need to store the friend list as an array. It's actually more efficient to store it as a set of user ids. That way, you're automatically guaranteed that each user id can be in the set only once.

    Users: {
       12345: "Rayega",
       67890: "Morse",
       24680: "Tanya",
       13579: "Julian",
       86420: "Mary",
       97531: "Powers"
    },
    UserFriends: {
       12345: {
          13579: true,
          86420: true,
          97531: true
       },
       67890: {
          86420: true,
          24680: true,
          97531: true
       }
    }
    

    That last structure is called an index and is covered in the Firebase documentation under creating data that scales.

提交回复
热议问题