I have this collection:

{ "MAIN": { "A":{row:"smth","Smth4example":"smth"}, "B":{row:"smth2","Smth4example":"smth2"} } } 

How do I display an object by key A:

 {row:"smth","Smth4example":"smth"} 

    2 answers 2

    Correct to make such a request:

     db.collectionName.find({"MAIN.A":{$exist: true}}, {_id:0, "MAIN.A":1}) 

    Such a query will return all fields A, from all documents in which it is.

      It turned out like this:

       db.collectionName.distinct('MAIN.A') 
      • one
        This code will really return the field A. However, if you have several documents with the same values, you will not know about it, because distinct will filter them out for uniqueness - Dmytryk