Created
February 23, 2019 18:03
-
-
Save Bilguun132/fcc4f34c5ff99d25094df065ad31cb18 to your computer and use it in GitHub Desktop.
MongoDemo-Tutorial-Index.js with schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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