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

Wrong TS type for upsertedId (can be null)

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      What problem are you facing?

      updateOne returns a null upsertedId (but doc and TS type do not allow that).

      What driver and relevant dependency versions are you using?

      mongodb@4.4.1

      Steps to reproduce?

      Just look at the code: https://github.com/mongodb/node-mongodb-native/blob/5132bc9d8ba816b0d98e1fceb6dfc96be0beb1da/src/operations/update.ts#L174

       

      Btw you should refactor your code, you should not have been able to return a null value for a non nullable field. You should remove Document from callback arg union type or at least check that the value you give to the callback match UpdateResult type.

            Assignee:
            Unassigned Unassigned
            Reporter:
            js@stairwage.com Jérôme Senot
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: