Database

db={"customers":[{"_id":1},{"_id":2}],"documents":[{"customerId":1},{"customerId":1},{"customerId":2}]}

Query

db.customers.aggregate([{$lookup:{from:"documents",let:{localField:"$_id"},pipeline:[{$match:{$and:[{$expr:{$eq:["$customerId","$$localField"]}}]}}],as:"recentDocuments"}},{$set:{"totalDocuments":{$size:"$recentDocuments"}}}])

Result