12 - Chain Search Query Helpers Narrow Search Result - MongoDB and Mongoose - freeCodeCamp Tutorial
Ganesh H
We can move the callback function inside the exec() method. This allows us to chain other methods together before that allow us to filter and narrow down our results. We can make use of the sort(), limit() and select() methods to do this.
Link to challenge : https://www.freecodecamp.org/learn/apis-and-microservices/mongodb-and-mongoose/chain-search-query-helpers-to-narrow-search-results Written Guide : https://www.notion.so/ganeshh123/Chain-Search-Query-Helpers-to-Narrow-Search-Results-85aa6c88fe9943449a27e5bf363a01f3
Full Playlist for this course : https://www.youtube.com/playlist?list=PLhGp6N0DI_1QJMb63oecYZ3lLjrF4PnIs All Writen Guides for this course : https://www.notion.so/ganeshh123/6f987e7260914612b06adf840dbb00c3 All My Tutorials can be found at : https://www.notion.so/Tutorials-Ganesh-H-293ea420d34a464f9a1907e0405b5f26
0:00 - Introduction
0:53 - exec() Executes the query. Inside a Callback function is specified, taking in error and any returned data. https://mongoosejs.com/docs/api/query.html#query_Query-exec
1:50 - sort() Sets the sort order. If an object is passed, values allowed are asc, desc, ascending, descending, 1, and -1. If a string is passed, it must be a space delimited list of path names. The sort order of each path is ascending unless the path name is prefixed with - which will be treated as descending. https://mongoosejs.com/docs/api/query.html#query_Query-sort
3:58 - limit() Specifies the maximum number of documents the query will return. https://mongoosejs.com/docs/api/query.html#query_Query-limit
4:35 - select() Specifies which document fields to include or exclude (also known as the query "projection"). A projection must be either inclusive or exclusive. In other words, you must either list the fields to include (which excludes all others), or list the fields to exclude (which implies all other fields are included). The _id field is the only exception because MongoDB includes it by default. 6:30 - Challenge Solution
-————————————————————————————————————- MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL).
Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js. It manages relationships between data, provides schema validation, and is used to translate between objects in code and the representation of those objects in MongoDB.
freeCodeCamp (also referred to as “Free Code Camp”) is a non-profit organization that consists of an interactive learning web platform, an online community forum, chat rooms, online publi ... https://www.youtube.com/watch?v=s4PKwa1Xpgs
39935143 Bytes