5/26/2018 - 11:48 AM

mongo db

connect, create new item

var mongoose = require("mongoose");


//create the cat scheme
var catScheme = new mongoose.Schema({
    name: String,
    age: Number,
    temperament: String

var Cat = mongoose.model("Cat", catScheme);

//thats how you create a new item (cat here)
var george = new Cat({
    name: "George",
    age: 11,
    temperament: "Grouchy"
}); (err, cat) { //callback run when save finished
    if (err) {
        console.log("SOMTHiNG WENT WRONG");
    else {
        console.log("WE JUST SAVE A CAT TO THE DB");