mongodb get total count with aggregate documents code example
Example: mongodb aggregate count
#return the number of documents whose "field" field has a value of A
query = db.collection.aggregate([{
"$match": {
"field": "A"
}
},{
"$count": "number of occurrences"
}])