简体   繁体   English

我想按值从 Firebase 实时数据库中删除值我没有它的关键

[英]I want to delete value from Firebase Realtime Databse by value i don't have it's key

I want to delete value from firebase realtime database by value I don't have it's key我想按值从 firebase 实时数据库中删除值我没有它的关键

I have database like:我有这样的数据库:

-root
  |
   --fittingHeight
     |
      --"timeStamp1":"1.1"
     |
      --"timeStamp2":"2.1" 

I want to delete 1.1 in this database but without key (timestamp1)我想删除此数据库中的 1.1 但没有密钥(时间戳 1)

You need to query the collection and then order it by its key您需要查询集合,然后按其键对其进行排序

 Query dbQuery = myRef.orderByKey();

Then you will need to add it a listener and use for loop on the results然后你需要给它添加一个监听器并在结果上使用 for 循环

dbQuery.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        for(DataSnapshot dst : dataSnapshot.getChildren()){
            if(...)
                myRef.child(dst.getKey()).removeValue();
                    }
            }
       }

This will remove all the values in that key so if you want to remove a specific value inside that key, add another for loop on its results.这将删除该键中的所有值,因此如果您想删除该键中的特定值,请在其结果上添加另一个 for 循环。

I want to delete 1.1 in this database but without key (timestamp1)我想删除此数据库中的 1.1 但没有密钥(时间戳 1)

There is no way you can use a query based on a property field which is dynamic.您无法使用基于动态属性字段的查询。 This is happening because, in order to delete a value, you need to know it's key.发生这种情况是因为,为了删除一个值,您需要知道它的键。

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Query query = rootRef.child("fittingHeight").orderByChild("timeStamp1").equalTo("1.1");

In Firebase Realtime Database there is no concept of wildcards.在 Firebase 实时数据库中没有通配符的概念。 So you always need to specify the name of the property.所以你总是需要指定属性的名称。 It's true that you can get the content of the entire fittingHeight object and do the filtering on the client but this solution isn't practical at all.确实可以得到整个fittingHeight object 的内容并在客户端进行过滤,但这种解决方案根本不实用。 A solution might be to change the database schema to have fixed properties, in a way that the above query can work.一种解决方案可能是将数据库模式更改为具有固定属性,以使上述查询可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Firebase 实时数据库中检索值? - How can I retrieve the value from Firebase Realtime database? 我有一个firebase数据库,我想从中访问一些嵌套节点,然后将数据列表添加到该特定节点 - i have a firebase databse from which i want to access some nested nodes then add a list of data to that particular node Firebase 实时数据库 DataSnapshot only 读取子项中的最后一个值 - Firebase Realtime Databse DataSnapshot only Read the last value in the child 我在 Firebase 控制台的实时数据库中看不到任何数据 - I don't see any data in my Realtime Database in Firebase's console 休眠:我不想删除孩子 - Hibernate: I don't want delete child 如何使用 firebase 实时数据库的字符串列表进行查询 - How do I make query with string list of firebase realtime databse 从嵌套节点 firebase 数据库中获取值 - get the value from nested node firebase databse 如何将我的数据(在键:值对中)推送到 android 中的 Firebase 实时数据库中? - How do I push my data (in key:value pair) into my Firebase realtime database in android? 我应该如何在 Firebase 实时数据库中设置键值类型的 getter 和 setter? - How should I set up getter and setter which is key - value type in Firebase Realtime Database? 如果我在其中使用变量,则实时数据库 endAt 方法不起作用 - Realtime databse endAt method doesn't work if I use variable in that
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM