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)); |
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({ |
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({ |
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
| Connected to MongoDB... | |
| { genre: [ 'action, adventure, fantasy' ], | |
| releaseDate: 2019-02-23T18:50:55.357Z, | |
| _id: 5c71960ff3e891294bf8c218, | |
| name: 'Avengers', | |
| director: 'Joss Whedon', | |
| price: 10, | |
| __v: 0 } | |
| { genre: [ 'animation, action, adventure' ], | |
| releaseDate: 2019-02-23T18:50:55.357Z, |
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
| async function updateMovie(id) { | |
| //query first | |
| const movie = await Movie.findById(id); | |
| if (!movie) return; | |
| movie.name = 'New Movie'; //or you can do movie.set({name:'New Movie'}) | |
| movie.save(); | |
| //update first | |
| const result = await Movie.update({_id: id}, { | |
| $set: {name: 'New Movie'} |
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
| //create MovieSchema | |
| const movieSchema = new mongoose.Schema({ | |
| name: { | |
| type: String, | |
| required: true, //built in validation logic | |
| minlength: 5, | |
| maxlength: 200 | |
| }, | |
| director: String, | |
| genre: { |
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
| async function createValidate() { | |
| const avengersMovie = new Movie({ | |
| director: 'Joss Whedon', | |
| genre: [], //NoSQL Db -> Document can be complex object unlike MySQL | |
| price: 10 | |
| }); | |
| try { | |
| await avengersMovie.save() | |
| console.log(avengersMovie); | |
| } |
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
| import 'package:flutter/material.dart'; | |
| //runApp calls MyApp | |
| void main() => runApp(MyApp()); | |
| //Stateless Widget since this class has no state, once created will be immutable | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| //A convenience widget that wraps a number of widgets that are commonly |
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
| import 'package:flutter/material.dart'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| //material app widget | |
| return MaterialApp( | |
| title: 'Crypto Price List', |
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
| import 'package:flutter/material.dart'; | |
| import 'dart:math'; | |
| import 'dart:async'; | |
| import 'dart:convert'; | |
| import 'dart:core'; | |
| import 'package:http/http.dart' as http; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { |