How in MongoDb to get documents only "top level" , that is, a list of documents without subdocuments ?

For example, there is a collection of Category documents with fields: Id (int), Name (string), Products (Product [])

You need to get a list of all categories, without pulling the list of products for each of them. How to do it?

    1 answer 1

    You can exclude the Products object from the selection by passing to find in the second parameter the list of fields to be selected

    db.collection.find({conditions}, {Products: 0}) // в результате будут все поля кроме Products 

    Read more in the documentation.