Advertisement
nikolayneykov

Untitled

Mar 17th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const mongoose = require('mongoose')
  2. const Schema = mongoose.Schema
  3.  
  4. const catSchema = new Schema({
  5.     name: { type: String, required: true },
  6.     age: { type: Number }
  7. })
  8.  
  9. const Cat = mongoose.model('cats', catSchema)
  10.  
  11. mongoose.connect('mongodb://localhost:27017/animals', { useNewUrlParser: true })
  12.     .then(() => {
  13.         console.log('Database online!')
  14.  
  15.         Cat.create({
  16.             name: 'Jani',
  17.             age: 4
  18.         })
  19.             .then(function () {
  20.                 Cat.find({}).then(c => c.forEach(c => console.log(`Zdrasti ${c.name}. I am ${c.age} years old :)`)));
  21.             });
  22.     })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement