// Update the other user that current user has asked for revision
export async function updateOtherUserForContractRevision(contractID : string, comments : any) {
   // getting userDetails
   let currentUser : string | any = localStorage.getItem("userDetails");
   currentUser = JSON.parse(currentUser);

   // update fields in contractRecieved
   const contractsRecievedRef : any =  doc(db, "contractsRecieved", currentUser.uid);
   
  //  const queryContractsRecieved = query(contractsRecievedRef,
  //   where('contractDetails.contract.contractID','array-contains',contractID)    
  //   );
  // console.log(".////////updateOtherUserForContractRevision", queryContractsRecieved ,contractID)

  onSnapshot(contractsRecievedRef, (doc: any) => {
    doc.data().contract.map((contract: any) => {
      if(contract.contractDetails.contract.contractID === contractID) {
        // I reach my desired array Index and want to update the msg field to my comments parametre
        console.log(".////////contract", contract);
      }
    })
  })
    


}

我想更新contract对象中的msg字段和content字段,它们依次出现在contract数组(第0个索引)中的contractDetails对象中.我已经使用onSnapShot搜索并达到了所需的数组值,如何在onSnapShot方法中更新这些字段?或者我应该使用另一种方法来搜索和更新数组包含的对象中的字段.

只是想一想:如果我能得到数组索引的引用,然后用它来更新对象,也许它会起作用

例如(我将更新sentForRevision)

 onSnapshot(contractsRecievedRef, async (doc: any) => {
    doc.data().contract.map(async (contract: any) => {
      if(contract.contractDetails.contract.contractID === contractID) {
        console.log(".////////contract", doc.ref);
        // If this contract.ref exists and points to the index present in the document
        await updateDoc(contract.ref,{
          "contractDetails.sentForRevision": true,
        });
      }
    })
  })

firebase

推荐答案

无法基于数组中包含的对象中存在的值来查询Firestore集合.这种过滤是不可能实现的.我甚至写了一篇关于这个话题的文章,名为:

如果需要,可以复制要对其执行过滤的数据,并将其添加到单独的数组中.这样,可以使用array-contains运算符查询集合.一旦获得所需的文档,就可以获得数组,执行更新,然后将文档写回Firestore.

Javascript相关问答推荐

获取表格的左滚动位置

Phaser框架-将子对象附加到Actor

当在select中 Select 选项时,我必须禁用不匹配的 Select

useNavigation更改URL,但不呈现或显示组件

有没有可能使滑动img动画以更快的速度连续?

如何将Openjphjs与next.js一起使用?

使用Google API无法进行Web抓取

正则表达式,允许我匹配除已定义的子字符串之外的所有内容

基于props 类型的不同props ,根据来自接口的值扩展类型

获取';无法解决导入和导入";slick-carousel/slick/slick-theme.css";';错误

为什么在函数中添加粒子的速率大于删除粒子的速率?

如何通过Axios在GraphQL查询中发送数组

顶点图使用组标签更新列之间的条宽

未捕获的不变违规:即使在使用DndProvider之后也应使用拖放上下文

递增/递减按钮React.js/Redux

如何在Firebase中读取对象的特定字段?

如何调整下拉内容,使其不与其他元素重叠?

react :图表负片区域不同 colored颜色

如何在函数组件中保留对计时器的引用

如何使用Angular JS双击按钮