I get this error message(“The field ‘count’ must be an accumulator object”, ), on lab 1, and I still cannot see what is wrong with the code. Please kindly help…!!
I have a similar problem, but I am not doing the count. I was just trying to find what room types are included in the airbnb database. I did this:
db.listingsAndReviews.aggregate( [{$project:{“room_type”:1, _id:0}}, {$group:{"_id" : “room_type”}}]).
I got no results. I did it exactly as the example during the lecture. What am I missing? Thanks to whoever reads these things.
The aggregation page doesn’t explain that an expression format should be different than what I have-- it mostly provides a list of the possible aggregate functions. The example used in the lesson shows the expression as “address.country.” But since in my task the field I want is a top level field, I do not need a period between the top level and sub-level. Otherwise, my script is identical. Also, the lesson page has a section that says // Group By Expression (which I assume is an instruction note and not to be part of the query). I tried to write it to match the format : { : }, like this: …{"_id":{ “$mergeObject”:“room_type”}}, and that returned an error. Same problem when I write {"_id":{“room_type”:{}}}. Can you direct me to the specific lesson? Thanks for your help.
Are you saying all I needed was to put the $ sign in front of the field? Like this:
db.listingsAndReviews.aggregate( [ {"$project":{“room_type”:1, “_id”:0}},{"$group":{"_id":"$room_type"}}])? I hope so. That sucks and was such a small item to overlook. It would have been nice if you just reminded me that I want to get the value of the field, which requires a slightly different format.