Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 602 Server Side development hw3 please explain and comment the following node.js code module.exports = { // host: 'localhost', // port: '27017', host: 'ds115768.mlab.com',

CS 602 Server Side development hw3 please explain and comment the following node.js code

module.exports = { // host: 'localhost', // port: '27017', host: 'ds115768.mlab.com', port: '15768', username: 'cs602_user', password: 'cs602_secret', database: 'cs602db' }

part 2

var mongoose = require('mongoose'); var Schema = mongoose.Schema;

var employeeSchema = new Schema({ firstName: String, lastName: String });

module.exports = { getModel: function getModel(connection) { return connection.model("EmployeeModel_sk", employeeSchema); } }

part 3

var mongoose = require('mongoose');

const credentials = require("./credentials.js");

const dbUrl = 'mongodb://' + credentials.username + ':' + credentials.password + '@' + credentials.host + ':' + credentials.port + '/' + credentials.database;

const connection = mongoose.createConnection(dbUrl);

var EmployeeDb = require('./employeeDb.js'); var Employee = EmployeeDb.getModel(connection);

connection.on("open", function(){ // create and save document objects var employee;

employee = new Employee({ firstName:'John',lastName:'Smith' }); employee.save();

employee = new Employee({ firstName:'Jane',lastName:'Smith' }); employee.save();

employee = new Employee({ firstName:'John',lastName:'Doe' }); employee.save(function(err) { connection.close(); if (err) throw err; console.log("Success!"); }); });

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Compute the mean and variance of (a) 1 0 tdB(t) (b) 1 0 t2 d B(t)

Answered: 1 week ago