Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想从Firebase获取文档数据_Javascript_Reactjs_React Native_Google Cloud Firestore_Expo - Fatal编程技术网

Javascript 我想从Firebase获取文档数据

Javascript 我想从Firebase获取文档数据,javascript,reactjs,react-native,google-cloud-firestore,expo,Javascript,Reactjs,React Native,Google Cloud Firestore,Expo,↑我想获取这些信息,但控制台上没有显示任何内容,尽管写入了console.logdoc.id、doc.data; console.logerror; 想 doc.id, doc.data() ↑我将console.log'abc'放在snapshot.forEachdoc=>{ abc显示在控制台上,所以我认为snapshot.forEachdoc=>{导致了一些错误。 然而,我不知道这有什么问题,所以我需要帮助来解决这个问题 换完衣服后,亲爱的巴罗斯 事实上,我不确定这是否是一个子集合。 你

↑我想获取这些信息,但控制台上没有显示任何内容,尽管写入了console.logdoc.id、doc.data; console.logerror; 想

doc.id, doc.data()
↑我将console.log'abc'放在snapshot.forEachdoc=>{ abc显示在控制台上,所以我认为snapshot.forEachdoc=>{导致了一些错误。 然而,我不知道这有什么问题,所以我需要帮助来解决这个问题

换完衣服后,亲爱的巴罗斯

事实上,我不确定这是否是一个子集合。 你能用这张照片确定这是不是子集合吗

console.logsnapshot亲爱的Shree Charan

改变


我以为您应该在获取快照之前调用get,而且js有async和await,我不明白您为什么要使用回调:const ref=await db.collection'users/${currentUser.uid}/memos'.orderBy'updatedAt','desc'.get then const docs=ref.docs.mapdoc=>doc.data;console.logdocs,但这需要包装在一个异步函数中。您介意记录快照的数据吗?它有数据还是空的?@Bargros谢谢您的帮助。我是一个业余爱好者,所以我只是按照您说的做了。我有一个解析此部分出错:const docs=ref.docs.mapdoc=>doc.data;我在谷歌上搜索了异步函数。但我还没有找到解决解析错误的方法。如果您同意,请告诉我为什么我的跳线不起作用。我将输入代码。@longuyễNánh感谢您的帮助…我将console.logsnapshot放在unsubscribe=ref.onSnapshotsnapshot=>{.snapshot的数据显示为非空!您能检查一下错误日志吗,您可能需要先在firestore上创建索引。我尝试了此操作,但无效…谢谢。
doc.id, doc.data()
snapshot.forEach((doc) => {
`useEffect(() => {
    const currentUser = firebase.auth();
    const db = firebase.firestore();
   async function asyncCall() {
    const ref = await db.collection('users/${currentUser.uid}/memos').orderBy('updatedAt', 'desc').get(),
    then
    const docs = ref.docs.map(doc => doc.data());
    console.log(docs);
    }
    asyncCall();
  });
    return (
      <Chart />
        );
    }`
t {
  "EP": t {
    "Je": Array [
      t {
        "dir": t {
          "name": "desc",
        },
        "field": e {
          "len": 1,
          "offset": 0,
          "segments": Array [
            "updatedAt",
          ],
        },
        "wn": false,
      },
    ],
    "Ze": "F",
    "collectionGroup": null,
    "en": null,
    "endAt": null,
    "filters": Array [],
    "limit": null,
    "path": e {
      "len": 3,
      "offset": 0,
      "segments": Array [
        "users",
        "undefined",
        "memos",
      ],
    },
    "startAt": null,
    "tn": null,
  },
  "firestore": t {
    "$E": t {
      "tl": [Function anonymous],
    },
    "BE": FirebaseAppImpl {
      "automaticDataCollectionEnabled_": false,
      "container": ComponentContainer {
        "name": "[DEFAULT]",
        "providers": Map {
          "app" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "app",
              "serviceProps": Object {},
              "type": "PUBLIC",
            },
            "container": [Circular],
            "instances": Map {
              "[DEFAULT]" => [Circular],
            },
            "instancesDeferred": Map {},
            "name": "app",
          },
          "platform-logger" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "platform-logger",
              "serviceProps": Object {},
              "type": "PRIVATE",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "platform-logger",
          },
          "fire-core-rn-version" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "fire-core-rn-version",
              "serviceProps": Object {},
              "type": "VERSION",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "fire-core-rn-version",
          },
          "fire-js-version" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "fire-js-version",
              "serviceProps": Object {},
              "type": "VERSION",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "fire-js-version",
          },
          "auth" => Provider {
            "component": Object {
              "instanceFactory": [Function instanceFactory],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "auth",
              "serviceProps": Object {
                "ActionCodeInfo": Object {
                  "Operation": Object {
                    "EMAIL_SIGNIN": "EMAIL_SIGNIN",
                    "PASSWORD_RESET": "PASSWORD_RESET",
                    "RECOVER_EMAIL": "RECOVER_EMAIL",
                    "VERIFY_EMAIL": "VERIFY_EMAIL",
                  },
                },
                "ActionCodeURL": [Function d],
                "Auth": [Function Lm],
                "AuthCredential": [Function kg],
                "EmailAuthProvider": [Function d],
                "Error": [Function M],
                "FacebookAuthProvider": [Function d],
                "GithubAuthProvider": [Function d],
                "GoogleAuthProvider": [Function d],
                "OAuthProvider": [Function d],
                "PhoneAuthProvider": [Function d],
                "RecaptchaVerifier": [Function d],
                "SAMLAuthProvider": [Function d],
                "TwitterAuthProvider": [Function d],
              },
              "type": "PUBLIC",
            },
            "container": [Circular],
            "instances": Map {
              "[DEFAULT]" => Object {
                "apiKey": "AIzaSyA0Dg2wLA3WzYe5EEbFHec1YwCDeFwqiUw",
                "appName": "[DEFAULT]",
                "authDomain": "assets-5744f.firebaseapp.com",
                "currentUser": null,
              },
            },
            "instancesDeferred": Map {},
            "name": "auth",
          },
          "auth-internal" => Provider {
            "component": Object {
              "instanceFactory": [Function instanceFactory],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "auth-internal",
              "type": "PRIVATE",
            },
            "container": [Circular],
            "instances": Map {
              "[DEFAULT]" => Object {
                "addAuthTokenListener": [Function bound ],
                "getToken": [Function bound ],
                "getUid": [Function bound ],
                "removeAuthTokenListener": [Function bound ],
              },
            },
            "instancesDeferred": Map {},
            "name": "auth-internal",
          },
          "fire-auth-version" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "fire-auth-version",
              "serviceProps": Object {},
              "type": "VERSION",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "fire-auth-version",
          },
          "database" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": true,
              "name": "database",
              "serviceProps": Object {
                "DataSnapshot": [Function DataSnapshot],
                "Database": [Function Database],
                "INTERNAL": Object {
                  "dataUpdateCount": [Function dataUpdateCount],
                  "forceLongPolling": [Function forceLongPolling],
                  "forceWebSockets": [Function forceWebSockets],
                  "interceptServerData": [Function interceptServerData],
                  "isWebSocketsAvailable": [Function isWebSocketsAvailable],
                  "setSecurityDebugCallback": [Function setSecurityDebugCallback],
                  "stats": [Function stats],
                  "statsIncrementCounter": [Function statsIncrementCounter],
                },
                "Query": [Function Query],
                "Reference": [Function Reference],
                "ServerValue": Object {
                  "TIMESTAMP": Object {
                    ".sv": "timestamp",
                  },
                },
                "TEST_ACCESS": Object {
                  "ConnectionTarget": [Function RepoInfo],
                  "DataConnection": [Function PersistentConnection],
                  "RealTimeConnection": [Function Connection],
                  "forceRestClient": [Function forceRestClient],
                  "hijackHash": [Function hijackHash],
                  "queryIdentifier": [Function queryIdentifier],
                },
                "enableLogging": [Function enableLogging],
              },
              "type": "PUBLIC",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "database",
          },
          "fire-rtdb-version" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "fire-rtdb-version",
              "serviceProps": Object {},
              "type": "VERSION",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "fire-rtdb-version",
          },
          "storage" => Provider {
            "component": Component {
              "instanceFactory": [Function factory],
              "instantiationMode": "LAZY",
              "multipleInstances": true,
              "name": "storage",
              "serviceProps": Object {
                "Reference": [Function Reference],
                "Storage": [Function Service],
                "StringFormat": Object {
                  "BASE64": "base64",
                  "BASE64URL": "base64url",
                  "DATA_URL": "data_url",
                  "RAW": "raw",
                },
                "TaskEvent": Object {
                  "STATE_CHANGED": "state_changed",
                },
                "TaskState": Object {
                  "CANCELED": "canceled",
                  "ERROR": "error",
                  "PAUSED": "paused",
                  "RUNNING": "running",
                  "SUCCESS": "success",
                },
              },
              "type": "PUBLIC",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "storage",
          },
          "fire-gcs-version" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "fire-gcs-version",
              "serviceProps": Object {},
              "type": "VERSION",
            },
            "container": [Circular],
            "instances"...(truncated to the first 10000 characters)
t {
  "SP": null,
  "gP": t {
    "Je": Array [
      t {
        "dir": t {
          "name": "desc",
        },
        "field": e {
          "len": 1,
          "offset": 0,
          "segments": Array [
            "updatedAt",
          ],
        },
        "wn": false,
      },
    ],
    "Ze": "F",
    "collectionGroup": null,
    "en": t {
      "Ye": "users/undefined/memos|f:|ob:updatedAtdesc,__name__desc,",
      "collectionGroup": null,
      "endAt": null,
      "filters": Array [],
      "limit": null,
      "orderBy": Array [
        t {
          "dir": t {
            "name": "desc",
          },
          "field": e {
            "len": 1,
            "offset": 0,
            "segments": Array [
              "updatedAt",
            ],
          },
          "wn": false,
        },
        t {
          "dir": t {
            "name": "desc",
          },
          "field": e {
            "len": 1,
            "offset": 0,
            "segments": Array [
              "__name__",
            ],
          },
          "wn": true,
        },
      ],
      "path": e {
        "len": 3,
        "offset": 0,
        "segments": Array [
          "users",
          "undefined",
          "memos",
        ],
      },
      "startAt": null,
    },
    "endAt": null,
    "filters": Array [],
    "limit": null,
    "path": e {
      "len": 3,
      "offset": 0,
      "segments": Array [
        "users",
        "undefined",
        "memos",
      ],
    },
    "startAt": null,
    "tn": Array [
      t {
        "dir": t {
          "name": "desc",
        },
        "field": e {
          "len": 1,
          "offset": 0,
          "segments": Array [
            "updatedAt",
          ],
        },
        "wn": false,
      },
      t {
        "dir": t {
          "name": "desc",
        },
        "field": e {
          "len": 1,
          "offset": 0,
          "segments": Array [
            "__name__",
          ],
        },
        "wn": true,
      },
    ],
  },
  "iP": undefined,
  "metadata": t {
    "fromCache": false,
    "hasPendingWrites": false,
  },
  "nP": t {
    "$E": t {
      "tl": [Function anonymous],
    },
    "BE": FirebaseAppImpl {
      "automaticDataCollectionEnabled_": false,
      "container": ComponentContainer {
        "name": "[DEFAULT]",
        "providers": Map {
          "app" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "app",
              "serviceProps": Object {},
              "type": "PUBLIC",
            },
            "container": [Circular],
            "instances": Map {
              "[DEFAULT]" => [Circular],
            },
            "instancesDeferred": Map {},
            "name": "app",
          },
          "platform-logger" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "platform-logger",
              "serviceProps": Object {},
              "type": "PRIVATE",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "platform-logger",
          },
          "fire-core-rn-version" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "fire-core-rn-version",
              "serviceProps": Object {},
              "type": "VERSION",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "fire-core-rn-version",
          },
          "fire-js-version" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "fire-js-version",
              "serviceProps": Object {},
              "type": "VERSION",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "fire-js-version",
          },
          "auth" => Provider {
            "component": Object {
              "instanceFactory": [Function instanceFactory],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "auth",
              "serviceProps": Object {
                "ActionCodeInfo": Object {
                  "Operation": Object {
                    "EMAIL_SIGNIN": "EMAIL_SIGNIN",
                    "PASSWORD_RESET": "PASSWORD_RESET",
                    "RECOVER_EMAIL": "RECOVER_EMAIL",
                    "VERIFY_EMAIL": "VERIFY_EMAIL",
                  },
                },
                "ActionCodeURL": [Function d],
                "Auth": [Function Lm],
                "AuthCredential": [Function kg],
                "EmailAuthProvider": [Function d],
                "Error": [Function M],
                "FacebookAuthProvider": [Function d],
                "GithubAuthProvider": [Function d],
                "GoogleAuthProvider": [Function d],
                "OAuthProvider": [Function d],
                "PhoneAuthProvider": [Function d],
                "RecaptchaVerifier": [Function d],
                "SAMLAuthProvider": [Function d],
                "TwitterAuthProvider": [Function d],
              },
              "type": "PUBLIC",
            },
            "container": [Circular],
            "instances": Map {
              "[DEFAULT]" => Object {
                "apiKey": "AIzaSyA0Dg2wLA3WzYe5EEbFHec1YwCDeFwqiUw",
                "appName": "[DEFAULT]",
                "authDomain": "assets-5744f.firebaseapp.com",
                "currentUser": Object {
                  "apiKey": "AIzaSyA0Dg2wLA3WzYe5EEbFHec1YwCDeFwqiUw",
                  "appName": "[DEFAULT]",
                  "authDomain": "assets-5744f.firebaseapp.com",
                  "createdAt": "1612675890112",
                  "displayName": null,
                  "email": "user1@example.com",
                  "emailVerified": false,
                  "isAnonymous": false,
                  "lastLoginAt": "1613219679007",
                  "phoneNumber": null,
                  "photoURL": null,
                  "providerData": Array [
                    Object {
                      "displayName": null,
                      "email": "user1@example.com",
                      "phoneNumber": null,
                      "photoURL": null,
                      "providerId": "password",
                      "uid": "user1@example.com",
                    },
                  ],
                  "redirectEventId": null,
                  "stsTokenManager": Object {
                    "accessToken": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjYxMDgzMDRiYWRmNDc1MWIyMWUwNDQwNTQyMDZhNDFkOGZmMWNiYTgiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vYXNzZXRzLTU3NDRmIiwiYXVkIjoiYXNzZXRzLTU3NDRmIiwiYXV0aF90aW1lIjoxNjEzMjE5Njc5LCJ1c2VyX2lkIjoiZjZmT0UzQ3hpWlN4ekFiekwxYXdIZ01uZXRJMyIsInN1YiI6ImY2Zk9FM0N4aVpTeHpBYnpMMWF3SGdNbmV0STMiLCJpYXQiOjE2MTMyODc2MDgsImV4cCI6MTYxMzI5MTIwOCwiZW1haWwiOiJ1c2VyMUBleGFtcGxlLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJ1c2VyMUBleGFtcGxlLmNvbSJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn19.U-OXeXG2kXtFAn0WmKHNYk7xTldRIHOrHloVBT41NWP5JVFWhG1I6fjmvNTQO1fBVtfSlL6Vjdohgeu7A1jrAs-WoJewaHQUEq--_3JklJ1p7elrnfqbrOsOBrwf6_41Tw4FPV3qmzlv5w-h2mvhG3qeFgyjR3YYAUn8jeRVgjx4HHvv59KLKUTEUq8NGR3UeGDVvifiwVOVGMmRZ2Ttq91m4F19W4Y-mT4sM-rbMZgd2XW5-W-Knz6wh3QmWWzULlHEA6Fo8uImNJ8tflJ755sBmHFbpJhvA39pjk0kSKWKKEOavI9s7c5zh_Zf94fpbAGu2myxwySp5BaoTbk5bg",
                    "apiKey": "AIzaSyA0Dg2wLA3WzYe5EEbFHec1YwCDeFwqiUw",
                    "expirationTime": 1613291205148,
                    "refreshToken": "AOvuKvRyJkAs06AhzjWZtlFbCqXxbmYKGZnqVNivNPnbWpOFnZQ-83LawZKhmzCsgH7e7Q8hE5QF3J886YMeoc1xf2-bgpppT1HJo2jkCRFYAvDNlMRlWaFm2AUeYlzJuG5iO53iRcwSFKDajlSgZfEy07N_H8fntDEFmuF_jwM0RTxqkQC-l4KaoTCYs6dgXTv00nt8y6uN",
                  },
                  "tenantId": null,
                  "uid": "f6fOE3CxiZSxzAbzL1awHgMnetI3",
                },
              },
            },
            "instancesDeferred": Map {},
            "name": "auth",
          },
          "auth-internal" => Provider {
            "component": Object {
              "instanceFactory": [Function instanceFactory],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "auth-internal",
              "type": "PRIVATE",
            },
            "container": [Circular],
            "instances": Map {
              "[DEFAULT]" => Object {
                "addAuthTokenListener": [Function bound ],
                "getToken": [Function bound ],
                "getUid": [Function bound ],
                "removeAuthTokenListener": [Function bound ],
              },
            },
            "instancesDeferred": Map {},
            "name": "auth-internal",
          },
          "fire-auth-version" => Provider {
            "component": Component {
              "instanceFactory": [Function anonymous],
              "instantiationMode": "LAZY",
              "multipleInstances": false,
              "name": "fire-auth-version",
              "serviceProps": Object {},
              "type": "VERSION",
            },
            "container": [Circular],
            "instances": Map {},
            "instancesDeferred": Map {},
            "name": "fire-auth-version",
          },
          "database" => Provider {
            "component": Component {
              "instanceFacto...(truncated to the first 10000 characters)

unsubscribe = ref.onSnapshot((snapshot) => {
snapshot.forEach((doc) => {
  console.log(doc.id, doc.data());
  });
 }, (error) => {
console.log(error);
 });
unsubscribe = ref.onSnapshot((snapshot) => {
snapshot.docs.forEach((doc) => {
  console.log(doc.id, doc.data());
  });
 }, (error) => {
console.log(error);
});