我如何从某个特定字段为空的Firebase获取记录 [英] How can I get records from Firebase where a certain field is empty

查看:38
本文介绍了我如何从某个特定字段为空的Firebase获取记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个需要小批量处理5k +任务的应用程序.为此,我有一个存储在Firebase中的任务队列.我希望能够以空状态提取一定数量的任务,更新其状态并写回.

I'm building an app where I need to process 5k+ tasks in small batches. For that I have a queue of tasks that is stored in a Firebase. I'd like to be able to pull certain amount of tasks with empty status, update their status and write back.

当前,我看不到如何在某个字段为空的情况下提取数据.是否可以?如果没有,那是什么替代解决方案?

Currently I don't see how I can pull data where a certain field is empty. Is it possible? If not, what would be the alternative solution?

更新02/12 .这是我拥有的数据结构:

UPDATED 02/12. Here is the data structure that I have:

{
  "-KAMnc89C5Yi_ef18ewc" : {
    "0": {
      "url": "https://excample.com/url",
      "status": "done"
    },
    "1": {
      "url": "https://excample.com/url1"
    },
    "2": {
      "url": "https://excample.com/ur2"
    },
    "3": {
      "url": "https://excample.com/ur3"
    }
}

这是我正在使用的查询:

And this is the query I'm using:

queueRef.orderByChild('status').equalTo(null).limitToFirst(1).once('value', function(snapshot) {
  console.log(snapshot.val());
});

queueRef 从上面的数据指向-KAMnc89C5Yi_ef18ewc" .

我希望得到一个对象-"1",但是我得到了所有对象.有什么我想念的吗?

I expect to get one object - "1", but instead I'm getting all of them. Is there something I'm missing?

推荐答案

Firebase不允许您存储没有值的属性.这只是意味着该属性不存在.

Firebase doesn't allow you to store a property without a value. That simply means that the property doesn't exist.

幸运的是,这并没有太大关系,因为这似乎可行.鉴于此数据结构:

Luckily this doesn't really matter too much, because this seems to work. Given this data structure:

{
  "-KADbswYg3FiQF78mmUf": {
    "name": "task1",
    "status": "done"
  },
  "-KADbugr7QzTx0s93Fs0": {
    "name": "task2"
  },
  "-KADbvKvBgiAXxnQvoBp": {
    "name": "task3"
  }
}

这有效:

ref.orderByChild('status').equalTo(null).once('value', function(snapshot) { 
  console.log(snapshot.val()); 
})

这将打印 task2 task3 .

这篇关于我如何从某个特定字段为空的Firebase获取记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆