Firestore选择where not not null [英] Firestore select where is not null

查看:160
本文介绍了Firestore选择where not not null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用firebase来管理我的项目,我无法使用where子句创建一个查询,其中某些值不为null。

I'm using firebase to manage my project and I cannot get to create a query with a where clause where some value is not null.

示例:我有一组员工。每个都有一个设备列表作为对象,其中键是设备ID,值是颜色。

Example: I have a collection of employees. Each have a list of equipments as an object where the key is the equipment id and the value a color.

user = {
    firstName: 'blabla',
    lastName: 'bloblo',
    equipments: {
        123: 'blue',
        124: 'red'
    }
}

我想让所有在设备中拥有某种设备的员工。让我们说123.

I would like to get all the employees who has a certain equipment in the equipments. Lets say 123.

来自Employees的Select *,其中equipment.123不为null。我试过了:

It comes to Select * from Employees where equipments.123 is not null. I've tried:

firestore.collection('employees').where(`equipments.${equipmentId}`, '!=', null)

但它不起作用。

我似乎无法使其发挥作用。你能帮助我。

I can't seems to make it work. Can you help me.

推荐答案

Firestore没有不等于运算符。但是看一下逻辑,你要做的是查询 String 的值,而不是 null 。如果将字符串传递给 where() Firestore可以执行此操作 > function。

Firestore has no "not equal" operator. But looking at the logic, what you're trying to do is query for values which are String, and not null. Firestore can do that if you pass a String to the where() function.

所以你可以做的是查询低于 \ uf8ff 的值。这是Unicode范围内的一个非常高的代码点。由于它是在Unicode之后的大多数常规字符之后,此查询将返回类型为 String 的所有内容:

So what you can do is query for values lower than \uf8ff. That's a very high code point in the Unicode range. Since it is after most regular characters in Unicode, this query will return everything that is of type String:

firestore.collection('employees').where('equipments.${equipm‌​entId}', '<', '\uf8ff')

或者您只需查询高于的值(空字符串):

Or you can simply query for values higher than "" (empty String):

firestore.collection('employees').where('equipments.${equipm‌​entId}', '>', '')

这篇关于Firestore选择where not not null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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