如何导入 @react-native-firebase FilterFunction?

huangapple go评论65阅读模式
英文:

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();

huangapple
  • 本文由 发表于 2023年6月1日 21:34:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76382459.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定