React Native FirebaseError:函数Query.startAfter()需要有效的第一个参数,但未定义该参数

React Native FirebaseError:函数Query.startAfter()需要有效的第一个参数,但未定义该参数,firebase,react-native,google-cloud-firestore,react-native-firebase,Firebase,React Native,Google Cloud Firestore,React Native Firebase,因此,我收到一个错误或: 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.setSta

因此,我收到一个错误或:

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{
“_文件”:文件{
“转换器”:[函数匿名],
"
},
“名称”:对象{
“stringValue”:“NoviMatko”,
},
“文本”:对象{
“stringValue”:“因为六个人做得很好。”,
},
“时间戳”:对象{
“integerValue”:“1604771339487”,
},
“uid”:对象{
“stringValue”:“S2BxNARp4Cfinttb1TK5mzAHPb13”,
},
},
“名称”:“projects/eleph-6fee9/databases/(默认)/documents/posts/djoSXIPRn1RMxMq2TD4C”,
“更新时间”:“2020-11-07T17:49:00.119930Z”,
},
“版本”:快照版本{
“时间戳”:时间戳{
“纳秒”:119930000,
“秒”:1604771340,
},
},
},
"
“[默认值]”=>对象{
“apiKey”:“AIzaSyDwUBce3WYEl78xA6aag5nzb1xh2xC8dZQ”,
“lastLoginAt”:“1604691856267”,
“电话号码”:空,
“photoURL”:空,
“providerData”:数组[
反对{
“displayName”:空,
“电子邮件”:dwdwadw@gmail.com",
“电话号码”:空,
“photoURL”:空,
“providerId”:“密码”,
“uid”:dwdwadw@gmail.com",
},
],
“重定向事件ID”:空,
},
“租户ID”:空,
“uid”:“S2BxNARp4Cfinttb1TK5mzAHPb13”,
},
},
},
“instancesDeferred”:映射{},
“名称”:“授权”,
},
},
“容器”:[Ci…(截断到前10000个字符)
得到了所有的结果
VVBQMRWDMSEBXCPDJ15=>{“化身”:空,“名称”:“NoviMatko”,“文本”:“Evooo”,“时间戳”:1605303464278,“uid”:“S2BxNARP4CFINTTB1TK1T5MZAHPB13”}
vG9p4xL8UqlZBkls1Xv1=>{“化身”:null,“名称”:“NoviMatko”,“文本”:“GDG”,“时间戳”:1605303411975,“uid”:“S2BXNARP4CFINTTB1TK15MZAHPB13”}
xyyZQs5q9OLP2BdqDwJO=>{“化身”:null,“名称”:“NoviMatko”,“文本”:“jkj”,“时间戳”:1605136211563,“uid”:“S2BxNARp4Cfinttb1TK5mzAHPb13”}
jttcmEM8WFHOXxRIO9q9=>{“化身”:null,“名称”:“NoviMatko”,“文本”:“adawdjnnajodhjadjonadjajdhajadjandjnadajdnjas”,“时间戳”:1605116149227,“uid”:“S2BxNARp4Cfinttb1TK5mzAHPb13”}

qFJwWiS0dpaKFbVOWrG1=>{“avatar”:null,“name”:“NoviMatko”,“text”:“gsefgsfsf错误消息告诉您,
check.data().id
未定义,而不是
check
。如果您想查看
check.data().id
的值,您应该准确地记录该值

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

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


有关更多信息,请参阅。

这对我很有帮助。谢谢你。我需要做的是理解我没有id字段,我必须将自动id与字段id相等,然后在这里使用它。非常感谢你
 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":"gsgsefgsfsfThe error message is telling you that 
check.data().id
was undefined, not
check
. If you want to see the value of
check.data().id
, you should log exactly that.

What's likely happening here is that the document you have in hand here doesn't have a property called "id". That would explain why you're seeing this error message.

If you want to use
startAfter()
correctly, you should actually just pass the entire DocumentSnapshot object to it:

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