Mark Rosenberg
Mark Rosenberg

Reputation: 15

Admin SDK update returning code 5: no entity to update

I'm trying to update an existing document in firestore. The document definitely exists. The data being sent from the client has all the data from the document itself (every field and value as well as the document id auto-generated by firestore).

I have tried each value of data that gets passed to the Firebase function: data.id (auto-gen id), data.email, data.name, to create a reference to the document to update, but still getting the error response. However, the .then and .catch blocks are both being executed each time the function fires.

As I said before, the document exists in the database in the 'users' collection. How do I reference that from the admin SDK?

Here is the function being called:

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

    admin.firestore().collection('users').doc(data.id).update({
        streamID: '98273498237'
    }).then(
        console.log('update success')
    ).catch(error => {
        console.log('error message: ', error)
    });
});

Here is the error message I am getting in the terminal:

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

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

Upvotes: 0

Views: 1570

Answers (2)

Voltron
Voltron

Reputation: 47

Gee, it would be nice if there was an eslint plugin to check for unreturned promises (or code paths failing to call response.send() ) similar to the way eslint-plugin-promise checks for nested promises

Better to get a lint error than a runtime bug

Upvotes: -1

Doug Stevenson
Doug Stevenson

Reputation: 317477

As described in the documentation, you need to return a promise that resolves with the data you want to send back to the client. If you start some async work without dealing with the promise (update() returns a promise), then the function will shut down and the work won't complete.

    return admin.firestore().collection('users').doc(data.id).update({
        streamID: '98273498237'
    }).then(
        console.log('update success')
        return { your: "response" }
    ).catch(error => {
        console.log('error message: ', error)
        return { your: "error" }
    });

You should return a response that makes sense for your client app.

In order to write effective cloud functions, you will definitely need to understand how JavaScript promises work.

Upvotes: 3

Related Questions