Last active
July 19, 2016 05:17
-
-
Save stevenspads/7ebb57d4a1fedddd9944138cd50c5c4e to your computer and use it in GitHub Desktop.
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
/* MONK */ | |
//1. | |
$npm install -—save monk | |
//2. in your route (ex: index.js) | |
var express = require('express'); | |
var router = express.Router(); | |
var db = require('monk')('localhost:27017/test'); //MongoDB database named 'test' | |
var userData = db.get('user-data'); //get the user-data collection from test in MongoDB | |
/* MONGOOSE */ | |
//1. | |
$npm install —-save mongoose | |
//2. in your route (ex: index.js) | |
var mongoose = require('mongoose'); | |
mongoose.connect('localhost:27017/test'); | |
var Schema = mongoose.Schema; | |
//create a Model Schema/layout | |
var userDataSchema = new Schema({ | |
title: {type: String, required: true}, | |
content: String | |
}, {collection: 'user-data'}); //set the MongoDB's collection name for this schema | |
//define the UserData Model and set the Model's schema | |
var UserData = mongoose.model('UserData', userDataSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment