JavaScript字符串内的参数未被识别。

huangapple go评论58阅读模式
英文:

Javascript parameter inside string not recognized

问题

以下是您要翻译的内容:

"For Firebase Cloudfunctions I am trying to update a value based on a dynmaic ID. This ID is saved inside a const value. The exact field I try to reach via dot-notation. Here is my complete function:

exports.badgeUpdated = functions.firestore .document("badges/{docId}") .onUpdate(async (change, context ) => { // get the document that has changed and the new fieldvalue const ObjectId = change.after.id; const newObject = change.after.data(); const newBadgeName = newObject.badgeName; // const newImageUrl = newObject.badgeImageUrl; console.log(`New BadgeName ${newBadgeName}`); console.log(`New BadgeID ${ObjectId}`); // Search badge doc with changed ID and set new name const querySnapshot = await admin .firestore() .collectionGroup("keekzCards") .where("badgeContains", "array-contains", ObjectId).get(); querySnapshot.forEach((doc) => { doc.ref.update({"badges.${ObjectId}.badgeName": newBadgeName}); console.log(doc.id); }); // console.log(`Queryresult ${(querySnapshot).docs}`); return null; });

The code itself is working, however instead of updating the field the function is creating an individual map-field using the plain string instead of resolving the underlying constant value. So after running the function my firestore document is looking like so:

JavaScript字符串内的参数未被识别。

EDIT: When exchaning the quotes the following error appears: JavaScript字符串内的参数未被识别。

1: https://i.stack.imgur.com/nv7nd.png 2: https://i.stack.imgur.com/WYuVB.png"

英文:

For Firebase Cloudfunctions I am trying to update a value based on a dynmaic ID.
This ID is saved inside a const value. The exact field I try to reach via dot-notation.
Here is my complete function:

exports.badgeUpdated = functions.firestore
    .document("badges/{docId}")
    .onUpdate(async (change, context ) => {
      //  get the document that has changed and the new fieldvalue
      const ObjectId = change.after.id;
      const newObject = change.after.data();
      const newBadgeName = newObject.badgeName;
      //  const newImageUrl = newObject.badgeImageUrl;
      console.log(`New BadgeName ${newBadgeName}`);
      console.log(`New BadgeID ${ObjectId}`);
      //  Search badge doc with changed ID and set new name
      const querySnapshot = await admin
          .firestore()
          .collectionGroup("keekzCards")
          .where("badgeContains", "array-contains", ObjectId).get();
      querySnapshot.forEach((doc) => {
        doc.ref.update({"badges.${ObjectId}.badgeName": newBadgeName});
        console.log(doc.id);
      });
      // console.log(`Queryresult ${(querySnapshot).docs}`);
      return null;
    });

The code itself is working, however instead of updating the field the function is creating an individual map-field using the plain string instead of resolving the underlying constant value. So after running the function my firestore document is looking like so:

JavaScript字符串内的参数未被识别。

EDIT:
When exchaning the quotes the following error appears:
JavaScript字符串内的参数未被识别。

答案1

得分: 1

ObjectId是一个保留关键字。避免使用它。改用objectIdoId代替:

const objectId = change.after.id;
英文:

ObjectId is a reserved keyword. Avoid using it. Use instead objectId or oId:

const objectId = change.after.id;

huangapple
  • 本文由 发表于 2023年3月4日 02:37:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630736.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定