A test driven experience on MongoDB CURD operations using mongoose and mocha.
A good walk through of core fundamentals of MongoDB
- Data Modelling and schema designs
- Handling Relational Data
- Handling Big collections with pagination
Clone and install:
git clone https://github.com/hemanth09/mongodb-curd-operations-and-unit-testing-with-mongoose-mocha.git
cd mongodb-curd-operations-and-unit-testing-with-mongoose-mocha
npm/yarn install
These packages will be installed
- Mongoose is a library which helps to modify the database.
- Mocha testing framework is popular for testing Nodejs and we are going to test create, read, update and delete operations on our MongoDB database.
Run it using:
npm run test
Before that you have to start MongoDb and connect to it. I am assuming you have MongoDB already installed on your computer. We will start the daemon specifying the location of the database.
mongod --dbpath=/User/username/data/db
If not installed follow the below link to install mongodb
- Installing Mongo
- Robo 3T You can install Robo 3T which gives a good user interface to manage your MongoDB database.
.
├── src # Src folder
└── user # user schema to create a user
├── test # Test folder
├── create_test # creating a user record
├── delete_test # deleting a user record
├── reading_test # Reading a user record
└── update_test # Updating a user record
- test/association_test
- test/middleware_test
- test/pagination_test