Excluding a subdocument

MongoDB version 3.1.13

excluding a subdocument not working .

db.collections.find({“name”:“riya”},{“address”:0})

db.collections.find({“name”:“riya”},{“address.$”:0})

I tried both but it is not excluding the subdocument

Hi @Gayathri_S,

The regular projection will not exclude specific arrays elements.

You Will need an aggregation with $filter projection:
https://docs.mongodb.com/manual/reference/operator/aggregation/filter/

Additionally, I am not sure why you are using a development version 3.1.13 and not a general available 3.6 - 4.4 versions.

Best
Pavel