更新时间:2021-08-27 19:07:04
封面
Title Page
Copyright and Credits
Advanced Node.js Development
Packt Upsell
Why subscribe?
PacktPub.com
Contributors
About the author
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Download the color images
Conventions used
Get in touch
Reviews
Getting Set Up
Installing MongoDB and Robomongo for Linux and macOS
Installing MongoDB and Robomongo for Windows
Creating and reading data
Summary
MongoDB Mongoose and REST APIs – Part 1
Connecting to MongoDB and writing data
Creating a directory for the project
Connecting the mongodb-connect file to the database
Adding a string as the first argument
Adding the callback function as the second argument
Error handling in mongodb-connect
Running the file in the Terminal
Adding data to the database
Adding a new record into a collection
The ObjectId
The _id property in the context of MongoDB
Calling the .getTimestamp function
Using object destructuring ES6
Creating a new instance of objectID
Fetching data
Fetching todos in Robomongo file
The find method
Writing a query to fetch certain values
Writing a query to fetch completed todos
Qureying todos by id
Implementing the count method
Querying users collection
Setting up the repo
Deleting documents
Exploring methods to delete data
The deleteMany method
The deleteOne Method
The deleteOne method
The findOneAndDelete method
Using the deleteMany and findOneAndDelete methods
Removing duplicate documents
Targeting the documents using ID
Running the findOneAndDelete and deleteMany statements
Making commit for the deleting documents methods
Updating data
MongoDB Mongoose and REST APIs – Part 2
Setting up Mongoose
Setting up root of the project
Connecting mongoose to database
Creating the todo model
Creating a brand-new Todo
Saving the instance to the database
Running the Todos script
Creating a second Todo model
Validators Types and Defaults
Mongoose validators
Customizing the Todo text property
Mongoose defaults
Mongoose types
Creating a Mongoose user model for authentication
Setting up the email property
Installing Postman
Making an HTTP request to Google
Illustrating working of the JSON data
Resource Creation Endpoint - POST /todos
Refactoring the server.js file to create POST todos route
Configuring the Todo and Users file
Loading Todo and User file in server.js
Configuring the Express application
Configuring the POST route
Getting body data from the client
Creating an instance of Mongoose model
Setting up HTTP status code
Testing POST /todos inside of Postman
Adding more Todos to the database
Testing POST /todos
Installing npm modules for testing POST /todos route
Setting up the test files
Loading the test files
Adding describe block for the test cases
Making the POST requests via supertest
Making assertions about the POST request
Making a request to fetch the Todos from the database
Adding the catch call for the error handling