I have a large dataset similar to below in mongoDB
I want to run an aggregation in MongoDB which would be the equivalent of this SQL:
SELECT SUM(cores) from machines
WHERE idc='AMS' AND cluster='1' AND type='Physical';
How do I go about going this in MongoDB?
[
{
"_id" : "55d5dc40281077b6d8af1bfa",
"hostname" : "x",
"domain" : "domain",
"description" : "VMWare ESXi 5",
"cluster" : "1",
"type" : "Physical",
"os" : "EXSi",
"idc" : "AMS",
"environment" : "DR",
"deviceclass" : "host",
"cores" : "64",
"memory" : "256",
"mounts" : [ ],
"roles" : [
"ESX-HOST"
],
"ipset" : {
"backnet" : "1"
},
"frontnet" : [ ],
"created" : "2015-09-08T07:35:03.343Z"
},
{
"_id" : "55d5dc40281077b6d8af1bfb",
"hostname" : "x",
"domain" : "domain",
"description" : "VMWare ESXi 5",
"cluster" : "1",
"type" : "Physical",
"os" : "EXSi",
"idc" : "AMS",
"environment" : "DR",
"deviceclass" : "host",
"cores" : "64",
"memory" : "256",
"mounts" : [ ],
"roles" : [
"ESX-HOST"
],
"ipset" : {
"backnet" : "1"
},
"frontnet" : [ ],
"created" : "2015-09-08T07:35:03.346Z"
}
]
.countbecause it SUM(_id) doesn't make sense here.