Aggregation gives back an empty Array

I am currently in chapter five of the course and probably did not understand something. I should output the value of room_type from all documents in the collection via aggregation.
I try it like this, because that was shown in the tutorial:

db.listingsAndReviews.aggregate([{$project:{"room_type":1, "_id":0}},{$group:{"_id":"$room_type"}}])

But this gives back an empty array.
Thanks for help

Can you show us screenshot.Do you get syntax error?
It works for me
Could be quotes issue


I too get the the correct answer.

I would check the following:

  • Verify that you are in the correct database by running use sample_airbnb.
  • Make sure the collection exists by running show collections.
  • Make sure you have the correct number of documents in the collection by running db.listingsAndReviews.countDocuments(). This should return the value of 5555.
1 Like

Thanks, it was a quotes issue. Because I have written “_id”, it must be without quotes.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.