I have the following update query, I want to use the value of the _id field. However, I can't, because _id is an ObjectId. and the field that I am writing on requires a string.
How to convert the _id to a string on the fly, within the request, in the concat function?
{ $concat: [`email`, ' #deleted(','$_id', ')'] }
full code if required:
await Model.findOneAndUpdate(req.params.id, [
{
$set: {
email: {
$concat: ['$email', ' #deleted(', '$_id', ')'],
},
_archived: Date.now(),
},
},
])
currently getting:
MongoServerError: Plan executor error during findAndModify :: caused by :: $concat only supports strings, not objectId