Firebase Real Time Database Structure for File Upload

前端 未结 2 1309
花落未央
花落未央 2021-01-27 04:31

I am working on my first Firebase project using AngularFire2. Below is the overall design of my learning project.

  • Users uploads photos and it\'s stored in the Fire
2条回答
  •  难免孤独
    2021-01-27 05:02

    I did the following based on Franks answer and it works. I am not sure if this is the best way for dealing with large number of data.

    getUploads() {
    
        return new Promise((resolve, reject) => {
          const rootDef = this.db.database.ref();
          const uploadsRef = rootDef.child('userUploads').orderByChild('time');
          const userRef = rootDef.child("userProfile");
          var uploads = [];
    
          uploadsRef.once("value").then((uploadSnaps) => {
    
            uploadSnaps.forEach((uploadSnap) => {
    
              var upload = uploadSnap.val();
    
              userRef.child(uploadSnap.val().user).once("value").then((userSnap) => {
                upload.displayName = userSnap.val().displayName;
                upload.avatar = userSnap.val().avatar;
                uploads.push(upload);
              });
            });
    
          });
    
          resolve(uploads);
        });
    
    }
    

提交回复
热议问题