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

Filter / UpdateFilter does not check nested properties in optional objects

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 4.8.1
    • 4.9.0
    • TypeScript
    • 0
    • Not Needed

    Description

      What problem are you facing?

      Both `Filter` and `UpdateFilter` types check top-level optional (nullable) properties, but they don't check nested properties inside a top-level optional (nullable) object property.

      What driver and relevant dependency versions are you using?

      • mongodb v4.8.1
      • typescript v4.7.4

      Steps to reproduce?

      import { Filter, UpdateFilter } from 'mongodb';
       
      interface Foo {
        optional?: string;
        optionalNested?: {
          path: string;
        };
        required: string;
        requiredNested: {
          path: string;
        };
      }
       
      const queryOptionalOK: Filter<Foo> = { optional: "foo", "optionalNested.path": "foo" };
      // ^ OK
      const queryOptionalFail: Filter<Foo> = { optional: 1, "optionalNested.path": 1 };
      // ^ Fail - TS flags only `optional`, but `optionalNested.path` should also be flagged
      const queryRequiredOK: Filter<Foo> = { required: "foo", "requiredNested.path": "foo" };
      // ^ OK
      const queryRequiredFail: Filter<Foo> = { required: 1, "requiredNested.path": 1 };
      // ^ OK - Both fields are flagged
       
      const updateOptionalOK: UpdateFilter<Foo> = { $set: { optional: "foo", "optionalNested.path": "foo" } };
      // ^ OK - Expected
      const updateOptionalFail: UpdateFilter<Foo> = { $set: { optional: 1, "optionalNested.path": 1 } };
      // ^ Fail - TS flags only `optional`, but `optionalNested.path` should also be flagged
      const updateRequiredOK: UpdateFilter<Foo> = { $set: { required: "foo", "requiredNested.path": "foo" } };
      // ^ OK - Expected
      const updateRequiredFail: UpdateFilter<Foo> = { $set: { required: 1, "requiredNested.path": 1 } };
      // ^ OK - Both fields are flagged
      

      TS Playground

      Attachments

        Issue Links

          Activity

            People

              neal.beeken@mongodb.com Neal Beeken
              avaly@plexapp.com Valentin Agachi
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: