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

Collection methods allow properties that are not in Document

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

      What problem are you facing?

      When casting the type of Collection<Document> to an interface made by me, I noticed that the Collection methods still allow me to set properties that do not exist in the Document type. This is due to a bug in mongodb.d.ts line 3713 where it says

      ```ts
      export declare type MatchKeysAndValues<TSchema> = Readonly<Partial<TSchema>> & Record<string, any>;
      ```

      Where it should say

      ```ts
      export declare type MatchKeysAndValues<TSchema> = Readonly<Partial<TSchema>>;
      ```

      Unfortunately this file is not on github for some reason, which doesn't allow me to open a PR to fix it.

      What driver and relevant dependency versions are you using?

      mongodb v4.1.0

      Steps to reproduce?

      ```ts

      interface MyDocument

      {     foo: string     bar: number }

      db.collection<MyDocument>("test").insertOne({foo: "value", bar: 0, foobar: "other value"}) //This syntax is completely valid despite "foobar" not existing in the MyDocument interface

      ```

            Assignee:
            Unassigned Unassigned
            Reporter:
            rodrigoleitao25@gmail.com Rodrigo Leitão
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: