【问题标题】:Angular Firestore - I want get document ID's of collection and convert them to an arrayAngular Firestore - 我想获取集合的文档 ID 并将它们转换为数组
【发布时间】:2021-05-21 17:39:56
【问题描述】:

我想将我所有的文档 ID 转换为一个数组,以便执行array.includes() 查询。

这是我的代码 -

this.db.collection('camps', ref => ref.where('id', '==', "fxvb95"))
  .snapshotChanges().subscribe(data => { 
    data.forEach(doc => {
      const y = doc.payload.doc.data()['altUID'];
      console.log(y)
  });

这是日志中的结果

exampleUID1

exampleUID2

如何将这些更改为单个值或数组?

【问题讨论】:

    标签: angular typescript firebase google-cloud-firestore


    【解决方案1】:

    这样的事情可能会奏效:

    this.db
      .collection("camps", (ref) => ref.where("id", "==", "fxvb95"))
      .snapshotChanges()
      .subscribe((data) => {
        const myArray = [];
        data.forEach((doc) => {
          const y = doc.payload.doc.data()["altUID"];
          console.log(y);
          myArray.push(y);
        });
        console.log(myArray);
      });
    

    【讨论】:

      猜你喜欢
      • 2021-10-28
      • 2020-08-15
      • 2021-05-04
      • 2018-04-04
      • 2019-09-24
      • 1970-01-01
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多