Not able to catch the significance of {_id=0, title:1, runtime:1} in some queries

Could someone explain what the highlighted query in the following image does? I tried on my side, but the query isn’t returning anything with the additional part (_id=0, etc.,), whereas without that, I am getting results.

Thanks in advance.


Hey @jramanan

The highlighted part of the command is the projection, which determines the fields that are included, { field: 1} or excluded, { field: 0 }

With the following command I got returned documents form the movieDetails collection. Hope it helps.

db.movieDetails.find({ runtime: {$gte: 180}, 'tomato.meter': {$gte: 95}}, {_id: 0, title: 1, runtime: 1})

Verbatim of above is: to find any documents in the movieDetails collection that have a runtime greater than 180, and a tomato.meter value greater than 95; only return the title and runtime fields of those documents, while explicitly excluding the _id field.

1 Like

I see. That makes sense. Thanks a lot, @natac13 ! :slight_smile: