Setup

  • Installation
  1. npm install
  2. npm install mongoose –save
  • Command Prompt

“C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe”

  • Connecting to MongoDB

test/connection.js

const mongoose = require(‘mongoose’);
//ES6 Promises
mongoose.Promise = global.Promise;
//Connect to database before tests run
before(function(){
//Connect to Mongodb
mongoose.connect(‘mongodb://localhost/’);
mongoose.connection.once(‘open’, function(){
…;
done();
}).on(‘error’, function(error){
…;
});
});

project folder command prompt

node test/connection.js

models/databaseName.js

const mongoose = require(‘mongoose’);
const Schema = mongoose.Schema;
const DatabaseNameSchema = new Schema({
name: String,
age: Number
});

const DatabaseName = mongoose.model(‘databaseName’, DatabaseNameSchema);

model.exports = DatabaseName;

Advertisements

About bernadetteengleman

Hello, I am Bernadette from New York City. I moved here from Chicago in 2013. I am originally from the Philippines. I started studying web programming in 2015. I love it because I like making fun websites and web apps. The projects that I built so far are posted below. I like to cook and I love to travel. I also like to volunteer and I am a team leader with the non-profit organization, NYCares.
This entry was posted in MongoDB. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s