英文:
How can I import @react-native-firebase FilterFunction?
问题
我正在尝试使用一个 FilterFunction(https://rnfirebase.io/reference/firestore/filterfunction)。并且我复制了下面的示例代码
const snapshot = await firestore()
.collection('Users')
.where(
Filter.or(
Filter.and(Filter('user', '==', 'Tim'), Filter('email', '==', 'tim@example.com')),
Filter.and(Filter('user', '==', 'Dave'), Filter('email', '==', 'dave@example.com')),
),
)
.get();
(我参考了 https://rnfirebase.io/firestore/usage#filtering)
但是我无法从任何地方获得 Filter
。
它出现了这个错误消息。Cannot find name 'Filter'.
我该如何使用 FilterFunction?
英文:
I'm trying to use a FilterFunction(https://rnfirebase.io/reference/firestore/filterfunction).
And I copied a example as bellow
const snapshot = await firestore()
.collection('Users')
.where(
Filter.or(
Filter.and(Filter('user', '==', 'Tim'), Filter('email', '==', 'tim@example.com')),
Filter.and(Filter('user', '==', 'Dave'), Filter('email', '==', 'dave@example.com')),
),
)
.get();
(I referred it from https://rnfirebase.io/firestore/usage#filtering)
But I cannot get a Filter
from anywhere.
It occurs this error message. Cannot find name 'Filter'.
How Can I use FilterFunction?
答案1
得分: 1
为了解决这个问题并正确使用 Filter
函数,您需要确保正确从 rnfirebase
库导入它。
要从 FilterFunction
模块中使用 Filter
函数,您可以按照以下方式修改您的代码:
import { FilterFunction } from 'rnfirebase/firestore';
// 确保从正确的模块导入 'FilterFunction'
const snapshot = await firestore()
.collection('Users')
.where(
FilterFunction.or(
FilterFunction.and(FilterFunction('user', '==', 'Tim'), FilterFunction('email', '==', 'tim@example.com')),
FilterFunction.and(FilterFunction('user', '==', 'Dave'), FilterFunction('email', '==', 'dave@example.com')),
),
)
.get();
注意:代码部分没有进行翻译。
英文:
To resolve this issue and use the Filter
function correctly, you need to ensure that you import it correctly from the rnfirebase
library.
To use the Filter
function from the FilterFunction
module, you can modify your code as follows:
import { FilterFunction } from 'rnfirebase/firestore';
// Make sure to import the 'FilterFunction' from the correct module
const snapshot = await firestore()
.collection('Users')
.where(
FilterFunction.or(
FilterFunction.and(FilterFunction('user', '==', 'Tim'), FilterFunction('email', '==', 'tim@example.com')),
FilterFunction.and(FilterFunction('user', '==', 'Dave'), FilterFunction('email', '==', 'dave@example.com')),
),
)
.get();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论