简体   繁体   中英

Firebase Admin SDK configured to access wrong app

Hopefully this isn't too similar to another question I posted. I am trying to read/write to my app's database from Firebase Functions using the Admin SDK. Been having issues. Here is the function:

exports.createAssetMux = functions.https.onCall((data, context) => {

    console.log('data: ', data)

    return admin.firestore().collection('users').doc(data.id).get()
    .then((doc) => {
        console.log('firestore document: ', doc)
        return {data: 'success'}
    }).catch(error => {
        console.log('error message: ', error)
        return {data: 'there was an issue'}
    });


});

And here is the response:

firestore document:  DocumentSnapshot {
>    _fieldsProto: undefined,
>    _ref: DocumentReference {
>      _firestore: Firestore {
>        _settings: [Object],
>        _settingsFrozen: true,
>        _serializer: [Serializer],
>        _projectId: 'live-from-868ea',
>        registeredListenersCount: 0,
>        _lastSuccessfulRequest: 1590544300258,
>        _backoffSettings: [Object],
>        _preferTransactions: false,
>        _clientPool: [ClientPool]
>      },
>      _path: ResourcePath { segments: [Array] },
>      _converter: {
>        toFirestore: [Function: toFirestore],
>        fromFirestore: [Function: fromFirestore]
>      }
>    },
>    _serializer: Serializer { createReference: [Function (anonymous)] },
>    _readTime: Timestamp { _seconds: 1590544300, _nanoseconds: 250711000 },
>    _createTime: undefined,
>    _updateTime: undefined
>  }

When I try to write to the db, or update anything, this is the response I get:

error message:  Error: 5 NOT_FOUND: no entity to update: app: "dev~my-firestore"
path <
  Element {
    type: "users"
    name: "kPuVNXsFFIyhs3Qad06B"
  }
>

  code: 5,
  details: 'no entity to update: app: "dev~my-firestore"\n' +
    'path <\n' +
    '  Element {\n' +
    '    type: "users"\n' +
    '    name: "kPuVNXsFFIyhs3Qad06B"\n' +
    '  }\n' +
    '>\n',
  metadata: Metadata {
    internalRepr: Map(1) { 'content-type' => [Array] },
    options: {}
  }
}

Note: My actual app name has been replaced with my-firestore , but I think the issue is with the dev~ part before it, that part I left in place. Do I need to change some config setting? I've checked in every config file I have and none of them contain the dev~ part.

I was running firebase emulators:start which was starting up a dev db. It seems obvious now. Running firebase serve --only functions was the workaround I used if I didn't want to fuss with the emulators. It does connect right to your production db, so be careful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM