Skip to content

Instantly share code, notes, and snippets.

@Bilguun132
Created February 23, 2019 18:03
Show Gist options
  • Select an option

  • Save Bilguun132/fcc4f34c5ff99d25094df065ad31cb18 to your computer and use it in GitHub Desktop.

Select an option

Save Bilguun132/fcc4f34c5ff99d25094df065ad31cb18 to your computer and use it in GitHub Desktop.
MongoDemo-Tutorial-Index.js with schema
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/demo', {useNewUrlParser: true})
.then(()=> console.log('Connected to MongoDB...'))
.catch((err) => console.error('Could not connect to MongoDB...', err));
//create MovieSchema
const movieSchema = new mongoose.Schema({
name: String,
director: String,
genre: [String],
date: {
type: Date,
default: Date.now()
}
})
//Create Movie Class
//Compile Schema into a Model
const Movie = mongoose.model('Movie', movieSchema);
const movie = new Movie({
name: 'Avengers',
director: 'Joss Whedon',
genre: ['action, adventure, fantasy'] //NoSQL Db -> Document can be complex object unlike MySQL
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment