Firestore 文档创建导致 GrpcConnection 错误 Nuxt3

问题描述 投票:0回答:1

我想为我的 Nuxt3 应用程序使用 Firebase/Firestore SDK。当我想在我的 firestore 数据库中存储新文档时,它总是会导致以下错误:

@firebase/firestore:Firestore(10.11.0):GrpcConnection RPC“写入”流0x29b0fa74错误。代码:5 消息:5 NOT_FOUND:

这就是我存储数据的方式:

export const add = async (col: string, document: Object) => {
  // @ts-ignore
  const colRef = collection(firestoreDb, col);

  const docRef = await addDoc(colRef, document);

  return docRef;
};

完整代码可以在这里找到:https://github.com/julix14/attraction_stack/commit/a5a9c1110f57ad9c80ea425368efde4411a69c83

有人知道这个错误的含义、原因以及如何修复吗?

编辑: 我添加了日志记录以查看 firestoreDb 实例和 colRef:

    Firestore {
  _authCredentials:
   FirebaseAuthCredentialsProvider {
     authProvider:
      Provider {
        name: 'auth-internal',
        container: [ComponentContainer],
        component: null,
        instances: Map(0) {},
        instancesDeferred: Map(0) {},
        instancesOptions: Map(0) {},
        onInitCallbacks: Map(0) {} },
     currentUser: User { uid: null },
     tokenCounter: 0,
     forceRefresh: false,
     auth: null },
  _appCheckCredentials:
   FirebaseAppCheckTokenProvider {
     appCheckProvider:
      Provider {
        name: 'app-check-internal',
        container: [ComponentContainer],
        component: null,
        instances: Map(0) {},
        instancesDeferred: Map(0) {},
        instancesOptions: Map(0) {},
        onInitCallbacks: Map(0) {} },
     forceRefresh: false,
     appCheck: null,
     latestAppCheckToken: null },
  _databaseId: DatabaseId { projectId: 'activityapp-419511', database: '(default)' },
  _app:
   FirebaseAppImpl {
     _isDeleted: false,
     _options:
      { apiKey: 'AIzaSyAQVJufWha_adYk879BEpM4BwUl4XggkEc',
        authDomain: 'activityapp-419511.firebaseapp.com',
        databaseURL: undefined,
        projectId: 'activityapp-419511',
        storageBucket: 'activityapp-419511.appspot.com',
        messagingSenderId: '412317674095',
        appId: '1:412317674095:web:6792a01c7499d1ce44fb9a' },
     _config: { name: 'server', automaticDataCollectionEnabled: false },
     _name: 'server',
     _automaticDataCollectionEnabled: false,
     _container: ComponentContainer { name: 'server', providers: [Map] } },
  type: 'firestore',
  _persistenceKey: 'server',
  _settings:
   FirestoreSettingsImpl {
     host: 'firestore.googleapis.com',
     ssl: true,
     credentials: undefined,
     ignoreUndefinedProperties: false,
     localCache: undefined,
     cacheSizeBytes: 41943040,
     experimentalForceLongPolling: false,
     experimentalAutoDetectLongPolling: true,
     experimentalLongPollingOptions: {},
     useFetchStreams: true },
  _settingsFrozen: false,
  _queue:
   <ref *1> AsyncQueueImpl {
     tail: Promise { undefined },
     retryableOps: [],
     _isShuttingDown: false,
     delayedOperations: [],
     failure: null,
     operationInProgress: false,
     skipNonRestrictedTasks: false,
     timerIdsToSkip: [],
     backoff:
      ExponentialBackoff {
        queue: [Circular *1],
        timerId: 'async_queue_retry',
        initialDelayMs: 1000,
        backoffFactor: 1.5,
        maxDelayMs: 60000,
        currentBaseMs: 0,
        timerPromise: null,
        lastAttemptTime: 1714043517590 },
     visibilityHandler: [Function (anonymous)] } }

参考文献:

CollectionReference {
  converter: null,
  _query:
   QueryImpl {
     path: ResourcePath { segments: [Array], offset: 0, len: 1 },
     collectionGroup: null,
     explicitOrderBy: [],
     filters: [],
     limit: null,
     limitType: 'F',
     startAt: null,
     endAt: null,
     memoizedNormalizedOrderBy: null,
     memoizedTarget: null,
     memoizedAggregateTarget: null },
  type: 'collection',
  firestore:
   Firestore {
     _authCredentials:
      FirebaseAuthCredentialsProvider {
        authProvider: [Provider],
        currentUser: [User],
        tokenCounter: 0,
        forceRefresh: false,
        auth: null },
     _appCheckCredentials:
      FirebaseAppCheckTokenProvider {
        appCheckProvider: [Provider],
        forceRefresh: false,
        appCheck: null,
        latestAppCheckToken: null },
     _databaseId: DatabaseId { projectId: 'activityapp-419511', database: '(default)' },
     _app:
      FirebaseAppImpl {
        _isDeleted: false,
        _options: [Object],
        _config: [Object],
        _name: 'server',
        _automaticDataCollectionEnabled: false,
        _container: [ComponentContainer] },
     type: 'firestore',
     _persistenceKey: 'server',
     _settings:
      FirestoreSettingsImpl {
        host: 'firestore.googleapis.com',
        ssl: true,
        credentials: undefined,
        ignoreUndefinedProperties: false,
        localCache: undefined,
        cacheSizeBytes: 41943040,
        experimentalForceLongPolling: false,
        experimentalAutoDetectLongPolling: true,
        experimentalLongPollingOptions: {},
        useFetchStreams: true },
     _settingsFrozen: false,
     _queue:
      AsyncQueueImpl {
        tail: [Promise],
        retryableOps: [],
        _isShuttingDown: false,
        delayedOperations: [],
        failure: null,
        operationInProgress: false,
        skipNonRestrictedTasks: false,
        timerIdsToSkip: [],
        backoff: [ExponentialBackoff],
        visibilityHandler: [Function (anonymous)] } },
  _path: ResourcePath { segments: [ 'activities' ], offset: 0, len: 1 } }
javascript firebase google-cloud-firestore nuxt.js nuxtjs3
1个回答
0
投票

实际上代码是有效的,但是谷歌云中的数据存储存在问题,导致了错误。

setLogLevel("debug")
是解决这个问题所缺少的拼图。

© www.soinside.com 2019 - 2024. All rights reserved.