Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevenspads/7ebb57d4a1fedddd9944138cd50c5c4e to your computer and use it in GitHub Desktop.
Save stevenspads/7ebb57d4a1fedddd9944138cd50c5c4e to your computer and use it in GitHub Desktop.
/* 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