Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mongoose = require('mongoose');
- mongoose.connect('mongoose://localhost/cat_app',{ //cat_app =binuhat na js
- useNewUrlparser: true;
- useUnifiedTopology: true;
- });
- // creating a schema
- var catSchema = new mongoose.Schenma({
- name:String,
- age:Number,
- temperament: String
- });
- //creating the model,Cat will be the table name,it will follow the catSchema
- var Cat = mongoose.model('Cat',catSchema);
- //inserting to db
- var insert = new Cat({
- name:"Jonard",
- age: 10,
- temperament:"Happy Meal"
- });
- //Updates an existing document or inserts a new document, depending on its document parameter.
- insert.save(function(err,cat){
- if(err){
- console.log("error");
- }else{
- console.log("Successfully addded" +inser+)
- }
- });
- //finding
- insert.find({},funtion(err,cats){
- if(err){
- console.log("error");
- } else {
- console.log(cats);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement