简体   繁体   English

值所在的 Firebase 过滤器

[英]Firebase filter where value is

The following call:以下调用:

fDB.ref(`organization/${uid}/attendance/${date}`)
.once('value')
.then(d => console.log(d.val()))

returns an object like so:像这样返回一个对象:

{ '-Lz8YxH_n7a5C6wv5vrX': 'absent',
  '-Lz8YxHbn5iOCxaGUBZt': 'absent',
  '-Lz8YxHfQPKH5BaIJBK_': 'absent',
  '-Lz8YxHiwp8QZW3TqAFn': 'present',
  '-Lz8YxHjtMUkroeyT5bv': 'absent',
  '-Lz8YxHmHqDblmBY4jyx': 'absent',
  '-Lz8YxHo-e4AiOwwex0s': 'absent',
  '-Lz8YxHqQXWoaGOFRLrO': 'present',
}

how can I query ONLY the values that are absent?如何仅查询不存在的值? I tried:我试过:

fDB.ref(`organization/${uid}/attendance/`)
    .orderByChild(date)
    .equalTo('absent')
    .once('value')
    .then(d => console.log(d.val()))

The above returned null I also tried上面返回的 null 我也试过了

fDB.ref(`organization/${uid}/attendance/${date}`)
    .orderByKey()
    .equalTo('absent')
    .once('value')
    .then(d => console.log(d.val()))

Same thing null.同样的事情空。 How can I achieve it?我怎样才能实现它?

It will filter out using orderByValue on the date node with equalTo , allowing you to run filter in values:它将在具有equalTo的日期节点上使用orderByValue过滤掉,允许您在值中运行过滤器:

 fDB.ref(`organization/${uid}/attendance/${date}`)
    .orderByValue()
    .equalTo('absent')
    .once('value')
    .then(d => console.log(d.val()));

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM