I updated mongodb from v4 to v6 and now I do get a typescript error in my function which I do not understand:
async myFunction({
caseId,
id
}: FunctionInput): Promise<string> {
const Data = this.db.collection('data')
const query = { caseId }
const update = { $pull: { field: { id } } }
try {
await Data.updateOne(query, update)
return id
} catch (error) {
if (error instanceof MongoServerError) {
console.error(error)
}
throw error
}
}
I do get the typscript error
Argument of type '{ $pull: { field: { id: string; }; }; }' is not assignable to parameter of type 'Document[] | UpdateFilter<Document>'.
Type '{ $pull: { field: { id: string; }; }; }' is not assignable to type 'UpdateFilter<Document>'.
Type '{ $pull: { field: { id: string; }; }; }' is not assignable to type '{ $currentDate?: Record<string, true> | Record<string, { $type: "date" | "timestamp"; }> | undefined; $inc?: Record<string, NumericType | undefined> | undefined; ... 12 more ...; $bit?: Record<...> | ... 2 more ... | undefined; }'.
Types of property '$pull' are incompatible.
Type '{ field: { id: string; }; }' is not assignable to type 'PullOperator<Document>'.
Type '{ field: { id: string; }; }' is not assignable to type 'NotAcceptedFields<Document, readonly any[]>'.
Property 'field' is incompatible with index signature.
Type '{ id: string; }' is not assignable to type 'undefined'.ts(2345)
const update: {
$pull: {
field: {
id: string;
};
};
}
What am I doing wrong?