Skip to content

Instantly share code, notes, and snippets.

@jwo
Created July 6, 2017 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwo/d14418e8942192d0c74e353fe4792d98 to your computer and use it in GitHub Desktop.
Save jwo/d14418e8942192d0c74e353fe4792d98 to your computer and use it in GitHub Desktop.
sample schema for mongoose
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