-
Install mongoose
-
Create app.js file and make the connection with mongoose
-
Create models folder that contain schema for author and book
-
author schema:
- name ==> type: string, required with message: "Author name should be provided"
- age ==> type: Number
- nationality ==> type: String, required with message: "Author nationality should be provided"
- image ==> type: string, required with message: "Author image should be provided"
- gender ==> type: string
- books ==> array of bookSchema
-
book schema:
- title ==> type: string, required with message: "Book title should be provided"
- pages ==> type: Number, required with message: "Book pages should be provided"
- price: ==> type: Number, default: 0
- image ==> type: string, required with message: "Book image should be provided"
-
-
Add the author and book data we gave you in book_seed, author_seed:
- Write a command and run it ONCE for each model in app.js for example if we want to insert books from seed file:
const Book = require("./models/bookAndAuthor").Book; const seedBook = require("./book_seed"); Book.insertMany(seedBook, (err, books) => { if (err){ console.log(err)} console.log("added provided books data", books) mongoose.connection.close(); });
do the same for Author with author_seed data
-
Querying
- Add at least 2 new author and book
- Select:
Author.find({}, (err, authors) => { console.log(authors); mongoose.connection.close(); });- Find all male authors
- Find all authors that age grater than 44
- Find all authors in Kuwait country
- Find all the books that start with L or l
- Find all the books that have pages more than 250
- Select with OR, AND
- Find all authors that in Kuwait or Saudi Arabia
- Find all authors that have 3 books or more and their age grater than 35
- Select by exists or does not exist
- Author do not have a key of age
- Negative Selection
- Author are not from Saudi Arabia
- Update
- Update Osama Al Muslim age to be 45
- Remove
- Remove all book that have price less than 50
