Created
July 6, 2017 16:21
-
-
Save jwo/d14418e8942192d0c74e353fe4792d98 to your computer and use it in GitHub Desktop.
sample schema for mongoose
This file contains 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.Promise = require('bluebird'); | |
mongoose.connect('mongodb://localhost:27017/eighties'); | |
const gameSchema = new mongoose.Schema({ | |
name: {type: String, required: true}, | |
imageUrl: {type: String, required: true}, | |
tags: [String], | |
year: {type: Number, required: true}, | |
link: {type: String, required: true} | |
}) | |
const Game = mongoose.model('Game', gameSchema); | |
const game = new Game() | |
game.name = "Contra" | |
game.imageUrl = "The imageUrl" | |
game.year = 1985 | |
game.link = "The link" | |
game.save() | |
.then( function(game){ | |
console.log("Check mongo!") | |
}) | |
.catch( function(validationError){ | |
console.log("Sorry sucker!") | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment