-
-
Save azamsharp/98bbda3d3ab16bd654982a72a3224479 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose') | |
// definining the schema for the dish | |
let dishSchema = mongoose.Schema({ | |
name :String, | |
price : Number, | |
imageURL :String | |
}) | |
// compiling the schema into a model | |
const Dish = mongoose.model('Dish',dishSchema) | |
// exporting User model so it can be used/imported in other files | |
module.exports = Dish | |
const express = require('express') | |
const app = express() | |
const Dish = require('./schemas/dishSchema') | |
const mongoose = require('mongoose') | |
mongoose.connect('mongodb://localhost/nailaskitchen') | |
const db = mongoose.connection | |
db.once('open',function(){ | |
console.log("Database is connected!") | |
}) | |
// deleting a record | |
let idToFind = "5b39554359b57d1a2224e9cf" | |
Dish.findByIdAndRemove(idToFind,function(error,foundDish){ | |
console.log(foundDish) | |
}) | |
// updating a record | |
/* | |
let idToFind = "5b39554359b57d1a2224e9cf" | |
Dish.findByIdAndUpdate(idToFind,{ name : "Delicious Meat Balls" },function(error,updatedDish){ | |
console.log(updatedDish) | |
}) */ | |
// find by id | |
/* | |
let idToFind = "5b39554359b57d1a2224e9cf" | |
Dish.findById(idToFind,function(error,dish){ | |
console.log(dish) | |
}) */ | |
// saving a new dish | |
//let dish = new Dish({ name : "Meat Balls", price : 23.56, imageURL : "meatballsimageURL"}) | |
// saving a new dish | |
/* | |
dish.save(function(error,dish){ | |
if(error != null) { | |
console.log(error) | |
return | |
} | |
console.log(dish) | |
}) */ | |
app.listen(3000,function(){ | |
console.log("Server started....") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment