Count and sum usage

Please explain what should be done - mongoshell throws error but no idea as error so general.

db.listingsAndReviews.aggregate([

{$project: {“address”:1,"_id":0 }},

{$group: {"_id":"$address.country"}}, // comment : good to here so next step… just sum

{$group: {"_id":null, count:{$sum:1}}

])

So having a smaller number of ‘documents’ … now how to transform that ?

Also fails:
db.listingsAndReviews.aggregate([

{$project: {“address”:1,"_id":0 }},

{$group: {"_id":"$address.country"}},

{$count:“myTotal”}

])

This error message is unclear Error: clone(t={}){const r=t.loc||{};return e({loc:new Position("line"in r?r.line:this.loc.line,"col

Thanks !

Hi @Andrew_Watts,

Could you please share the screenshot of the error message with us, as it will give us more context of what specific solution we should provide to you!

Thanks,
Kushagra

found My mistake then closed the compass and reopened - and then lost it again seems like copying and pasting is introducing errors - I cannot figure out this new error.
2022-06-04 07_01_25-CN=Microsoft Windows, O=Microsoft Corporation, L=Redmond, S=Washington, C=US

Thanks

The closing brace } it is pointing at in the syntax error should be a closing parenthesis ) I think

1 Like