06 - Use model.findOne() to Return a Single Document - MongoDB and Mongoose - freeCodeCamp Tutorial

Published: 12 July 2020
on channel: Ganesh H
12,510
79

If we are just looking for one result, we can call the findOne() method on a model. Once again we give an object with our desired properties, and this time an object is returned. We also look at how we can look for items inside an array in the document, using the $all operator.

Link to challenge : https://www.freecodecamp.org/learn/ap...
Written Guide : https://www.notion.so/ganeshh123/Use-...

Full Playlist for this course :    • MongoDB and Mongoose - freeCodeCamp  
All Writen Guides for this course : https://www.notion.so/ganeshh123/6f98...
All My Tutorials can be found at : https://www.notion.so/Tutorials-Ganes...

Concepts:
model.findOne()
Behaves like .find(), but it returns only one document (not an array), even if there are multiple items. It is especially useful when searching by properties that you have declared as unique.
https://mongoosejs.com/docs/api.html#...

$all
The $all operator selects the documents where the value of a field is an array that contains all the specified elements.
https://docs.mongodb.com/manual/refer...

Models are fancy constructors compiled from Schema definitions. An instance of a model is called a document. Models are responsible for creating and reading documents from the underlying MongoDB database.
https://mongoosejs.com/docs/models.html

mongoose.model()
When you call mongoose.model() on a schema, Mongoose compiles a model for you. The first argument is the singular name of the collection your model is for. Mongoose automatically looks for the plural, lowercased version of your model name.
https://mongoosejs.com/docs/models.ht...
————————————————————————————————————
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 publications and local organizations that intend to make learning web development accessible to anyone. Beginning with tutorials that introduce students to HTML, CSS and JavaScript, students progress to project assignments that they complete either alone or in pairs. Upon completion of all project tasks, students are partnered with other nonprofits to build web applications, giving the students practical development experience.

Thanks for Watching!


Watch video 06 - Use model.findOne() to Return a Single Document - MongoDB and Mongoose - freeCodeCamp Tutorial online without registration, duration hours minute second in high quality. This video was added by user Ganesh H 12 July 2020, don't forget to share it with your friends and acquaintances, it has been viewed on our site 12,510 once and liked it 79 people.