Mongoose Fundamentals
Lesson 1 of 2
  1. 1
    Mongoose is a Node package that interacts with a running MongoDB database. Before learning about Mongoose, let’s define a couple of key terms: - Data - Database #### What is Data? Data in the…
  2. 2
    Mongo stores data in ‘binary’ JSON (BSON) documents. BSON documents have a similar structure to JavaScript objects. MongoDB stores documents in a collection. A MongoDB database is made up of t…
  3. 3
    Mongoose is a JavaScript library that provides methods to interact with a MongoDB database. Mongoose translates JavaScript objects (JSON) to BSON data in a MongoDB database, and vice versa. Mongoo…
  4. 4
    The key-value pair in a schema is called a path. Paths define the name and type of fields in a MongoDB document. const poemSchema = new mongoose.Schema({ title: String, body: [String], publ…
  5. 5
    In our original poetry application example we declared the schema type for our title as a String: const poemSchema = new mongoose.Schema({ title: String }) Often, we want to specify more than j…
  6. 6
    To use our poemSchema definition: const poemSchema = new mongoose.Schema({ title: String, }); we need to convert our poemSchema into a Model we can work with. Schemas provide the definition for…
  7. 7
    Our model is a class with properties that we define in our schema. We can construct documents as instances of our model. Creating documents and saving them to the database can be done by calling .c…
  8. 8
    At this point, we will start creating instances in a MongoDB database, then query the database for the values we saved. All of the method calls and queries will be passed to runWithDatabase(). I…
  9. 9
    Mongoose supports the creation of methods on both instances of documents and collections of documents (the model). - .statics() adds static “class” methods to the model. - .methods() adds an in…
  10. 10
    In this lesson, you learned how to use Mongoose to interact with a MongoDB database. Let’s review some of the topics that we covered: - Mongoose is a Node package that interacts with a running Mong…

What you'll create

Portfolio projects that showcase your new skills

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory