如何在Firestore上获取集合的每个文档的一个字段?

时间:2019-07-08 07:42:40

标签: angular google-cloud-firestore ionic4

我正在尝试仅收集一个集合中每个文档的一个字段。我正在做的是一种订阅方法来填充动态过滤器列表,但是我知道它不起作用,什么才是我想要的最佳方法?我想订阅它,这是我的代码:

this.af.collection('objects').valueChanges().subscribe(data => {        
  this.listTitles.push(data.title)
});

2 个答案:

答案 0 :(得分:0)

.subscribe在您的情况下不起作用,可能您需要像这样拆分代码,

this.objectCollectionRef = this.af.collection('objects');
this.objectCollection = this.objectCollectionRef.valueChanges();


for(let data of this.objectCollection){
   this.listTitles.push(data.title)
}

希望这会有所帮助!

答案 1 :(得分:-1)

只需映射结果并在模板中使用异步

 public function createThumbnail($videoUrl, $storageUrl, $fileName, $second, $width = 640, $height = 480) {
        $this->videoURL = $videoUrl;

        $this->storageURL = $storageUrl;
        $this->thumbName = $fileName;
        $this->fullFile = "{$this->storageURL}/{$this->thumbName}";

        $this->screenShotTime = $second;

        $this->width = $width;
        $this->height = $height;

        try {
            $this->create();
            $this->thumbnail();
            $this->resizeCropImage($this->width, $this->height, $this->fullFile, $this->fullFile);
        } catch (Exception $e) {
            Log::error($e->getMessage());
        }

        return $this;
    }



so u need to fix the file path by creating d folder for the file to be saved 

here my working code 

      $thumbnail_path=storage_path().'/app/public/thumbs';
                $file = $request->file('video');
               $thumbvideoPath  = storage_path('/app/public/videos/').$videoName;
                      $video_path       = $destination_path.'/'.$file_name;
                      $thumbnail_image  = $videoName.".jpg";

$thumbnail_status = VideoThumbnail::createThumbnail($thumbvideoPath,$thumbnail_path,$thumbnail_image, 10);

//dd($thumbnail_status);
   if($thumbnail_status)
   {
     echo "Thumbnail generated            ";
   }
   else
   {
     echo "thumbnail generation has failed";
   }

在您的模板中:

class YourComponent{
  listTitles:Observable<String>;

  constructor(){
    this.listTitles = this.af.collection('objects').valueChanges().pipe(
      map(objs => objs.map(obj => obj.title))
    )
  }
}
相关问题