**Why this code isn't working? **
let posts = await postsCollection.aggregate([
{$match: {_id: new ObjectID(id)}},
{$addFields: {authorId: { $toObjectId: "$author"}}},
{$lookup: {from: "users", localField: "author", foreignField: "_id", as: "authorDocument"}}
]).toArray()
Below should work.. I presume that postsCollection and users are the collection you want to join based on authorId as common key but its stored as string in postsCollection and as _id in users.
let posts = await postsCollection.aggregate([
{$match: {_id: new ObjectID(id)}},
{$addFields: {authorId: { $toObjectId: "$author"}}},
{$lookup: {from: "users", localField: "authorId", foreignField: "_id", as: "authorDocument"}}
]).toArray()
Note: you have used author but it should be authorId