Mongoose Snippet for reference
const mongoose = require('mongoose');
mongoose.set('useNewUrlParser', true);
mongoose.set('useFindAndModify', false);
mongoose.set('useCreateIndex', true);
mongoose.set('useUnifiedTopology', true);
const url = process.env.DATABASE_URL || 'mongodb://localhost/yelp-camp';
mongoose.connect(url);
const catSchema = new mongoose.Schema({
name: String,
age: Number,
temperament: String
});
const Cat = mongoose.model('Cat', catSchema);
let george = new Cat({
name: 'Ms. Norris',
age: 7,
temperament: 'Evil'
});
george.save((err, cat) => {
if (err) {
console.log('Something Went Wrong Nya!');
} else {
console.log('Cat Saved Nya!');
console.log(cat);
}
});
Cat.create(
{
name: 'snow white',
age: 15,
temperament: 'bland'
},
(err, cat) => {
if (err) {
console.log('whoops! :c ');
console.log(err);
} else {
console.log('everything okay nya!');
console.log(cat);
}
}
);
Cat.find({}, (err, cats) => {
if (err) {
console.log('whoops error');
console.log(err);
} else {
console.log('success nya!');
console.log(cats);
}
});