-
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.