Javascript Firebase equalTo不工作

Javascript Firebase equalTo不工作,javascript,firebase,firebase-realtime-database,Javascript,Firebase,Firebase Realtime Database,我在firebase中的数据如下所示 items { item1: { field1: value1 field2: value2 } item2: { field1: value4 field2: value3 } } 现在,我想得到field2==value3的所有项目。当我运行以下查询时,我将获得所有项目。为什么? firebase.database().ref().child('items') .o

我在firebase中的数据如下所示

items {
   item1: {
      field1: value1
      field2: value2
   }
   item2: {
      field1: value4
      field2: value3
   }
}
现在,我想得到field2==value3的所有项目。当我运行以下查询时,我将获得所有项目。为什么?

firebase.database().ref().child('items')
        .orderByChild('field2')
        .equalTo('value3')
        .limitToLast(10)
        .once('value');

您可以使用
child\u added
listener来代替查询,它将返回items中的所有子项,然后您可以执行所需的操作

firebase.database().ref('items').on('child_added', snap => {
    if(snap.val().field2 == 'value3') {
        console.log('Match found in ' + snap.key); //Match found in item2
    }
});

您可以使用
child\u added
listener来代替查询,它将返回items中的所有子项,然后您可以执行所需的操作

firebase.database().ref('items').on('child_added', snap => {
    if(snap.val().field2 == 'value3') {
        console.log('Match found in ' + snap.key); //Match found in item2
    }
});

您使用的是Firebase版本3 API还是旧版本2 API?代码看起来不正确。裁判在哪里?对于版本3 API,它类似于
firebase.database().ref().child(…
我使用的是最新版本。在代码中,firebase是我的局部变量,与firebase.database().ref()相等。让我更改问题的代码以便更清晰。你说你得到了“所有项目”。你得到了多少?你能在你的问题中包括收到的项目吗?@cartant抱歉,忽略这一点。我很愚蠢。有一个并行线程在没有过滤器的情况下设置了不同的结果。你使用的是Firebase版本3 API还是旧版本2 APIde看起来不正确。ref在哪里?对于版本3 API,它类似于
firebase.database().ref().child(…
我使用的是最新的。在代码中,firebase是我的局部变量,与firebase.database().ref()相等。让我更改问题的代码以提高清晰度。你说你得到了“所有项目”。你得到了多少?你能在你的问题中包括收到的项目吗?@cartant抱歉,忽略这个。我很愚蠢。有一个并行线程在没有过滤器的情况下设置了不同的结果。