【问题标题】:Firestore filtering by document referenceFirestore 按文档引用过滤
【发布时间】:2021-11-20 15:08:27
【问题描述】:

我正在尝试按 React Native 中的文档引用进行过滤。我正在使用react-native-firebase。我想要其字段(DocumentReference)在提供的数组中的所有文档:

 const subscriber = firestore()
        .collection('strategyCounts')
        .where(
          'strategy',
          'in',
          user.strategies.map(strategy => {
            return strategy.path;
          }),
        ).onSnapshot(...)

user.strategies 看起来像这样 ["/strategies/id", "/strategy/id2"]

【问题讨论】:

    标签: javascript firebase google-cloud-firestore react-native-firebase


    【解决方案1】:

    如果要按文档引用进行过滤,则需要在数组中传递DocumentReference 对象。所以像:

      user.strategies.map(strategy => {
        return firestore().doc(strategy.path);
      }),
    

    或(略短):

      user.strategies.map(strategy => firestore().doc(strategy.path)),
    

    【讨论】:

    • 是的,但没有返回任何内容。我添加了几张照片
    • 哦,我有另一个地方。作品:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 2018-04-29
    • 1970-01-01
    相关资源
    最近更新 更多