Mongo 4.0 Migration leads to FilterQuery type error compared to @types/mongodb

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Unknown
    • None
    • Affects Version/s: 4.2.2
    • Component/s: TypeScript
    • 1
    • None
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      What problem are you facing?

      I am facing an issue migrating from the MongoDB 3.x driver to version number 4 with Typescript support. I used @types/mongodb formerly and used the following code to get a typesafe filter object (for example the $regex property was typesafe):

      const filterObject: FilterQuery<{       mail: string;       name: string;       _id: string;  }> = name: { $regex: "
      b" + nameFilter + "[a-z]*", $options: "i" } };    
      return await db.collection(databaseName).find(filterObject).collation({ locale: "de" }).sort(mysort).toArray() 

      There is no FilterQuery type in the Mongo 4 typesafe so I use the equivalent (or so I think) "FilterOperations" which also gives me typesafety but gives me an typescript error when I want to pass it to the find function

      const filterObject: FilterOperations<

      {       mail: string;       name: string;       _id: string;     }

      >= name: { $regex: "
      b" + nameFilter + "[a-z]*", $options: "i" } };    
      return await db.collection(databaseName).find(filterObject).collation({ locale: "de" }).sort(mysort).toArray() 

      The error message is 

      What driver and relevant dependency versions are you using?

      Driver Version 4.2.2

      Steps to reproduce?

      Create the same FilterQuery and FilterOperations Type as me and try to pass the corresponding object to the find() function of MongoClient.db.

        1. Unbenannt.png
          61 kB
          _erikburghardt98@gmail.com
        2. Unbenannt2.png
          45 kB
          _erikburghardt98@gmail.com
        3. code.png
          26 kB
          _erikburghardt98@gmail.com
        4. typescript error.png
          84 kB
          _erikburghardt98@gmail.com
        5. code-1.png
          26 kB
          _erikburghardt98@gmail.com
        6. code-2.png
          26 kB
          _erikburghardt98@gmail.com

            Assignee:
            Unassigned
            Reporter:
            Some One
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: