Mongo Playground

Configuration

[{"key":1,name:"first"},{"key":2,name:"second"},{"key":1,name:"third"},{"key":1,name:"fourth"}]

Query

db.collection.aggregate([{"$match":{"key":1}},{"$count":"key"}])

Result