Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const mongoose = require('mongoose')
- const Schema = mongoose.Schema
- const catSchema = new Schema({
- name: { type: String, required: true },
- age: { type: Number }
- })
- const Cat = mongoose.model('cats', catSchema)
- mongoose.connect('mongodb://localhost:27017/animals', { useNewUrlParser: true })
- .then(() => {
- console.log('Database online!')
- Cat.create({
- name: 'Jani',
- age: 4
- })
- .then(function () {
- Cat.find({}).then(c => c.forEach(c => console.log(`Zdrasti ${c.name}. I am ${c.age} years old :)`)));
- });
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement