My code is as follows:
async function reply(collection: Collection, body: MyBody) {
const {reply} = body
if (!reply) return
await collection.findOneAndUpdate({
_id: new ObjectId(reply)
}, {
$inc: { subCount: 1},
$push: { children: reply }
})
}
But the compiler throws an error when I try to compile it to JS:
TS2322: Type { children: string; } is not assignable to type PushOperator<Document>
Type { children: string; } is not assignable to type NotAcceptedFields<Document, readonly any[]>
Property children is incompatible with index signature.
Type string is not assignable to type undefined
mongodb.d.ts(6361, 5): The expected type comes from property $push which is declared here on type UpdateFilter<Document>
The compiler says my $push is written incorrectly, but I don’t seem to be doing anything differently than the example in the documentation.
The dependency I’m using is nodejs mongodb@2.8.1.