Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4933

Type error when interpolating field name in $set

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: StrictFilter, TypeScript
    • None
    • 2
    • Not Needed
    • Not Needed

      What problem are you facing?

      When using dynamic variables for the $set key TypeScript gives an error, but if I hardcode it to a number then I don't get an error. I believe this is a typing issue because the following code shouldn't have any type errors.

      ```ts
      export interface AddStructureOptions

      {   player: Player;   structure: Structure; }

      export const addStructure = async (

      {   player,   structure, }

      : AddStructureOptions) =>

      {   player.bases[0].structures[structure.position] = structure;   await db.players.updateOne(     \{ _id: player._id }

      ,
          {
            $set: {
              [`bases.0.structures.${structure.position}`]: structure,
            },
          }
        );
      };
      ```

      What driver and relevant dependency versions are you using?

      4.13.0

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            junk@hornta.se hornta N/A
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: