The reason your map/reduce isn't working is that the pair of values you emit from your map has to include two things:
1. Key over which you want to aggregate values
2. Value
Your key should be a constant - i.e. you want to aggregate over the entire collection so you need to have all emitted values map to the same key.
Replace emit(this._id, 1)
with emit(null, 1)
and it will work (it doesn't have to be null
it could be 1
or `"collection" string literal or anything else that's constant).
Unless you are doing this as an exercise to learn map/reduce, I would recommend using db.collection.count()
to get the count of items in a collection.