We are going to create a mongoose model and use it!
-
Create a project folder named
cardealer
and navigate to it. -
Run
npm init
-
Run
npm install --save mongoose
-
Using mongoose models, create a model for the following document (car.js):
- A car
-
should have the following properties:
- make
- model
- color
- year
- meta:
- mpg
- msrp (manufacturer suggested retail price)
-
The car should have a method that outputs a string that describes the car.
- example output: "The <:color> <:make> <:model> is a beautiful car. It is eco-friendly. Consumes only <:meta.mpg> mpg!. With a tag price of <:meta.msrp> it's a bargain!"
-
- Using the node CLI
node
, require mongoose, and connect to the database:
// Connect to mongo db
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/cardealer');
- Require your car model:
// or ./models/car depending on where the file is located in the project
var Car = require('./car')
- Create 2 different cars and save them to the database.
Slack me the output of the following command:
var result = Car.find({}, function(err, cars){ console.log(cars) });