This is my mongodb collection model
export class User {
constructor(
public _id: ObjectId,
public username: string,
public phone: string,
public password: string,
public pages: Array<ObjectId>
) { }
}
I want to add new ObjectId into pages:
const pageID = new ObjectId()
const result1 = await userCollection.findOneAndUpdate({
_id: new ObjectId(userID)
}, {
$push: {
pages: pageID
}
})
And there is an error near $push
Type '{ pages: ObjectId; }' is not assignable to type 'PushOperator<Document>'.
Type '{ pages: ObjectId; }' is not assignable to type 'NotAcceptedFields<Document, readonly any[]>'.
Property 'pages' is incompatible with index signature.
Type 'ObjectId' is not assignable to type 'undefined'.
I found lots of examples in js and shell, but none in ts. Can anyone help me with that?