firebase grab by orderByChild then update results key

后端 未结 1 1728
时光说笑
时光说笑 2021-01-25 01:20

So i have this query and currently collects all the data with materialName equals to gold. I wanted change all to false.

// materialName = \"gold\"          


        
1条回答
  •  礼貌的吻别
    2021-01-25 01:45

    You need to loop over the results (since there can be multiple matching nodes) and then update each:

    database.ref('/app/posts')
      .orderByChild('material')
      .equalTo(materialName)
      .once('value', function (snapshot) {
        snapshot.forEach(function(child) {
          child.ref.update({material: false});
        });
    });
    

    You'll also note that I changed your .startAt().endAt() to an equalTo(), which gives the same results with less code.

    0 讨论(0)
提交回复
热议问题