# Change mapreduce to aggregate in device auth

**URL:** <https://hub.mender.io/t/change-mapreduce-to-aggregate-in-device-auth/214>\
**Category:** General Discussions\
**Created:** [February 12, 2019, 2:29pm UTC](https://hub.mender.io/t/change-mapreduce-to-aggregate-in-device-auth/214 "2019-02-12T14:29:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbbh](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@bbbh](https://hub.mender.io/u/bbbh)\
**Post date:** [February 12, 2019, 2:29pm UTC](https://hub.mender.io/t/change-mapreduce-to-aggregate-in-device-auth/214/1 "2019-02-12T14:29:35Z")

</div>

I am trying to use mongo atlas as a database, but they do not allow mapreduce on their smaller tiers. so line 835 in datastore\_mongo.go ([https://github.com/mendersoftware/deviceauth/blob/master/store/mongo/datastore\_mongo.go#L835](https://github.com/mendersoftware/deviceauth/blob/master/store/mongo/datastore_mongo.go#L835)) fails. I am not any good with go but i think i read it as take the collection and filter by device\_id given in the api call and then map reduce the return a sum of the statuses, but wouldnt that always return just one status not making mapreduce needed? or could i use this code instead?

```
	pipeline := []bson.M{
	bson.M{
		"$match": filter,
	},
	bson.M{
		"$group": bson.M{
			"_id": "$status", "total": 
			bson.M{
				"$sum": 1,
			},
		},
	},
}
err := c.Pipe(pipeline).All(&result)
```
