Projection in Mongo DB Projection refers to the ability to retrieve only the specific fields from a document that meet the criteria of a query. In other words: selecting only necessary data rather than selecting the whole data of the document The Find() method is used in projection. db.your_collection_name.find ({},{" field_name ": 1})
Advantages & Disadvantages Of Projection Advantages Reduced Data Transfer: By fetching only the required fields, it reduces the amount of data transferred over the network Improve performance: By retrieving only the necessary fields, it enhances query performance as it reduces the amount of data that needs to be processed by the database engine Disadvantages Possible Impact on Readability : Overusing projection and excluding essential fields from the query result could potentially impact the readability and comprehensibility of the retrieved data. Potential Overhead in Maintenance: If there are frequent changes in the required fields for retrieval, managing and updating projection parameters across multiple queries might introduce maintenance overhead.
Limit in Mongo DB Limits refers to the practice of restricting the number of documents returned by a query db.filed_name.find ().limit( numberof records you want to limit)
Advantages & Disadvantages Of Limits Advantages Improved Performance: Limiting the amount of data retrieved reduces the workload on the database server and can improve query performance Disadvantages Incomplete Data: Limiting data retrieval might result in incomplete information, especially if crucial fields or documents are excluded. Complex Querying Logic: Adding limitations into queries can sometimes complicate query logic, especially when combining multiple conditions or constraints
Advantages & Disadvantages Of Limits Advantages Enhanced Data Presentation: Sorting allows data to be presented in a structured and organized manner, for facilitating better reading Streamlined Analysis and Reporting: Sorting enables streamlined data analysis and reporting by arranging information in a specific order Disadvantages Impact on Query Performance : Sorting can affect the performance of queries, especially if sorting is performed on non-indexed fields or when sorting requires extensive computations due to the complexity of the sort key. Complexity: Implementing sorting logic in queries can sometimes introduce complexity, especially when dealing with multiple fields or complex sorting requirements.