【问题标题】:React Native FirebaseError: Function Query.startAfter() requires a valid first argument, but it was undefinedReact Native FirebaseError:函数 Query.startAfter() 需要有效的第一个参数,但未定义
【发布时间】:2020-11-14 00:39:20
【问题描述】:

所以我收到一个错误或:

FirebaseError:函数 Query.startAfter() 需要有效的 第一个参数,但它是未定义的。

我的代码:

getMore = async () => {
    let check = {};
    check = this.state.lastDoc;

    console.log(check); //returns a big object I will post below.
    if (check) {
      this.setState({ isMoreLoading: true });

      setTimeout(async () => {
        let snapshot = await firebase
          .firestore()
          .collection("posts")
          .orderBy("timestamp", "desc")
          .startAfter(check.data().id)
          .limit(2)
          .get();
  };

所以我猜这个错误是关于firebase

什么控制台日志(检查)在被使用之前返回 startAfter: 删了一点,因为它不能发布:删了一点 因为它无法发布:

 QueryDocumentSnapshot {
      "_document": Document {
        "converter": [Function anonymous],
        "
            },
            "name": Object {
              "stringValue": "NoviMatko",
            },
            "text": Object {
              "stringValue": "For wh perceive laughing six did far.",
            },
            "timestamp": Object {
              "integerValue": "1604771339487",
            },
            "uid": Object {
              "stringValue": "S2BxNARp4Cfinttb1TK5mzAHPb13",
            },
          },
          "name": "projects/eleph-6fee9/databases/(default)/documents/posts/djoSXIPRn1RMxMq2TD4C",
          "updateTime": "2020-11-07T17:49:00.119930Z",
        },
        "version": SnapshotVersion {
          "timestamp": Timestamp {
            "nanoseconds": 119930000,
            "seconds": 1604771340,
          },
        },
      },
    
          "
              
                  "[DEFAULT]" => Object {
                    "apiKey": "AIzaSyDwUBce3WYEl78xA6aag5nzb1xh2xC8dZQ",
                    
                      "lastLoginAt": "1604691856267",
                      "phoneNumber": null,
                      "photoURL": null,
                      "providerData": Array [
                        Object {
                          "displayName": null,
                          "email": "dwdwadw@gmail.com",
                          "phoneNumber": null,
                          "photoURL": null,
                          "providerId": "password",
                          "uid": "dwdwadw@gmail.com",
                        },
                      ],
                      "redirectEventId": null,
                    
                      },
                      "tenantId": null,
                      "uid": "S2BxNARp4Cfinttb1TK5mzAHPb13",
                    },
                  },
                },
                "instancesDeferred": Map {},
                "name": "auth",
              },
              
                },
                "container": [Ci...(truncated to the first 10000 characters)
    Got all results
    vVbq2mwrDMseBxCPDj15 => {"avatar":null,"name":"NoviMatko","text":"evoooo","timestamp":1605303464278,"uid":"S2BxNARp4Cfinttb1TK5mzAHPb13"}
    vG9p4xL8UqlZBkls1Xv1 => {"avatar":null,"name":"NoviMatko","text":"gdgdgdg","timestamp":1605303411975,"uid":"S2BxNARp4Cfinttb1TK5mzAHPb13"}
    xyyZQs5q9OLP2BdqDwJO => {"avatar":null,"name":"NoviMatko","text":"jkj","timestamp":1605136211563,"uid":"S2BxNARp4Cfinttb1TK5mzAHPb13"}
    jttcmEM8WFHOXxRIO9q9 => {"avatar":null,"name":"NoviMatko","text":"adawdadjnajodhjadjonadjjajdhajdnjadnjandjnadnadajdnjas","timestamp":1605116149227,"uid":"S2BxNARp4Cfinttb1TK5mzAHPb13"}
    qFJwWiS0dpaKFbVOWrG1 => {"avatar":null,"name":"NoviMatko","text":"gsgsefgsfsf????????????????","timestamp":1605115920543,"uid":"S2BxNARp4Cfinttb1TK5mzAHPb13"}
    qD8rrsexA4HrWHvCtfxR => {"avatar":null,"name":"NoviMatko","text":"JLKDBWJENKEFJOFBNKOJSBENFJKSNFJKLSNFJKSJNFJSKFNJSNFNSFNSNFNSJKLEFNSENFSNFJNSEJFNSJFNSJFNSEFNLSNF;SNFS;FH;SFJSFNSJFNSJNFJSNFJSNFNSNFNSFNSJFNSFNSF","timestamp":1605115869284,"uid":"S2BxNARp4Cfinttb1TK5mzAHPb13"}
    djoSXIPRn1RMxMq2TD4C => {"avatar":null,"name":"NoviMatko","text":"For who thoroughly her boy estimating conviction. Reme admire in giving. See resolved goodness felicity shy civility domestic had 
    but. Drawings offended yet answered jennings perceive laughing six did far.","timestamp":1604771339487,"uid":"S2BxNARp4Cfinttb1TK5mzAHPb13"}
    eILcb0rPOZ0Rpeoym6uX => {"avatar":"https://firebadia&token=272cfbff-3fd7-4216-a6c3-09ed612eca3e","text":"Fjjfjffj","timestamp":1604395119914,"uid":"oTPw7q2jRWcE3F92U4aXeHHTHDg1"}
    y7FN13SKWUDsWdKsGJiT => {"commentCount":3,"likeCount":5,"mood":"Yy","text":"Today is such 
    a joyful day because its Monday and at Mondays we dont do much at my work #blessed","timestamp":1592776918943,"userHandle":" NRQ2Ewhx76cWVqntRPLV1ygYHB73"}

【问题讨论】:

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


    【解决方案1】:

    错误消息告诉您check.data().id 未定义,而不是check。如果您想查看check.data().id 的值,您应该准确记录它。

    这里可能发生的情况是您手头的文档没有名为“id”的属性。这可以解释为什么您会看到此错误消息。

    如果你想正确使用startAfter(),你实际上应该将整个 DocumentSnapshot 对象传递给它:

            let snapshot = await firebase
              .firestore()
              .collection("posts")
              .orderBy("timestamp", "desc")
              .startAfter(check)
              .limit(2)
              .get();
    

    有关详细信息,请参阅documentation on the pagination APIs

    【讨论】:

    • 这对我有帮助。谢谢你。我真正需要做的是了解我没有 id 字段,我必须将 Auto Id 与字段 id 相等,然后在这里使用它。非常感谢你
    猜你喜欢
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多