MongoDB - distinct and count, the simplest case -
i have database xxx , collection yyy in mongodb (using mongolab).
here sample record:
{ "_id": { "$oid": "551a5asdfsdfsdfs" }, "_class": "com.test.com", "mvid": "d0fffsdfs" } i retrieve distinct values of field "mvid" , count them. here found on internet:
db.yyy.aggregate([{ $group: { _id: "$mvid"} },{ $group: { _id: 1, count: { $sum: 1 } } }]) i tried
xxx.yyy.aggregate([{ $group: { _id: "$mvid"} },{ $group: { _id: 1, count: { $sum: 1 } } }]) i put above command text box, in both cases following error message: "we encountered error while parsing json. please check syntax (e.g. ensure using double quotes around both field names , values) , try again."
what doing wrong?
that command text box providing json-formatted parameters whatever command selected in drop-down. aggregate not 1 of listed commands, appears you'd need install mongodb shell locally , remotely connect mongolab database , run command.
see this blog post details on installing mongodb shell , connecting mongolab.
Comments
Post a Comment