4
votes

Using Firestore in a React app, Im testing out using Google Cloud Functions to grab a document field, and then create a new field in Firestore using that field. I had it working the other day and now it is not.

This is the error that Im getting in the Google Cloud Function log:

Error: Cannot decode type from Firestore Value: {"stringValue":"sox"} at DocumentSnapshot._decodeValue

Below is the code I used. It is very similar to the code here: https://firebase.google.com/docs/firestore/extend-with-functions#writing_data

exports.createShowDoubleName = functions.firestore
  .document('shows/{showId}')
  .onUpdate((event) => {
    const data = event.data.data();
    const previousData = event.data.previous.data();
    if (data.name == previousData.name) return;
    var name = data.name;
    var newname = name+"_"+name
     return event.data.ref.set({
        newname: newname
      }, {merge: true});
});
4

4 Answers

1
votes

firebase-functions SDK version 0.7.5 is supposed to fix the problem. It now forces a peer dependency on firebase-admin 5.5.0. Get it:

npm install [email protected]
2
votes

I am not able to reproduce the error when running the latest version (0.7.4) of firebase-functions.

You must be running an older version because the current version of firebase-functions requires a trigger function to return a Promise or value. With the current version, this statement produces an error:

if (data.name == previousData.name) return;

and must be changed to:

if (data.name == previousData.name) return null;

Suggest you upgrade firebase-functions by running this command in the functions folder of your project:

npm install firebase-functions@latest --save
1
votes

I had the same issue and same error. After upgrading both firebase-functions and firebase-admin (npm install firebase-functions@latest --save) and (npm install firebase-admin@latest --save) it solved the issue. Delving further into the logs the issue seems to be in an old version of firebase-admin. I am now running admin version 5.5.1 and functions version 0.7.4.

1
votes

Definitely just need to update something.

Open your terminal navigate to the functions folder and run this update from there:

npm install firebase-functions@latest firebase-admin@latest --save