NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

index.js

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

var EmployeeSchema = new Schema({
name: {
first: {
type: String,
required: true
},
last: {
type: String,
required: true
}
},
team: {
type: Schema.Types.ObjectId,
ref: 'Team'
},
image: {
type: String,
default: 'images/user.png'
},
address: {
lines: {
type: [String]
},
postal: {
type: String
}
}
});

var Employee = mongoose.model('Employee', EmployeeSchema);
var db = mongoose.connection;
var dbUrl = 'mongodb://iagoabuu:timelapse11' + encodeURIComponent('$') + '@ds012538.mlab.com:12538/dbhrp';


console.log('db url is - ' + dbUrl);

var TeamSchema = new Schema({
name: {
type: String,
required: true
}
});
var Team = mongoose.model('Team', TeamSchema);
db.on('error', function () {
console.log('there was an error communicating with the database');
});



function insertTeams (callback) {
Team.create({
name: 'Product Development'
}, {
name: 'Dev Ops'
}, {
name: 'Accounting'
}, function (error, pd, devops, acct) {
if (error) {
return callback(error);
} else {
console.info('teams successfully added');
console.dir(pd);
console.dir(devops);
console.dir(acct);

callback(null, pd, devops, acct);
}
});
}
function insertEmployees (pd, devops, acct, callback) {
Employee.create([{
name: {
first: 'John',
last: 'Adams'
},
team: pd._id,
address: {
lines: ['2 Lincoln Memorial Cir NW'],
zip: 20037
}
}, {
name: {
first: 'Thomas',
last: 'Jefferson'
},
team: devops._id,
address: {
lines: ['1600 Pennsylvania Avenue', 'White House'],
zip: 20500
}
}, {
name: {
first: 'James',
last: 'Madison'
},
team: acct._id,
address: {
lines: ['2 15th St NW', 'PO Box 8675309'],
zip: 20007
}
}, {
name: {
first: 'James',
last: 'Monroe'
},
team: acct._id,
address: {
lines: ['1850 West Basin Dr SW', 'Suite 210'],
zip: 20242
}
}], function (error, johnadams) {
if (error) {
return callback(error);
} else {
console.info('employees successfully added');
callback(null, {
team: pd,
employee: johnadams
});
}
})
}




mongoose.connect(dbUrl, function (err) {
if (err) {
return console.log('there was a problem connecting to the database!' + err);
}
console.log('connected!');
insertTeams(function (err, pd, devops, acct) {
if (err) {
return console.log(err)
}
insertEmployees(pd, devops, acct, function (err, result) {
if (err) {
console.error(err);
} else {
console.info('database activity complete')
}
db.close();
process.exit();
});
});
});


================
single-emp.js

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

var EmployeeSchema = new Schema({
name: {
first: {
type: String,
required: true
},
last: {
type: String,
required: true
}
},
team: {
type: Schema.Types.ObjectId,
ref: 'Team'
},
image: {
type: String,
default: 'images/user.png'
},
address: {
lines: {
type: [String]
},
postal: {
type: String
}
}
}, { collection : 'employees' });

var Employee = mongoose.model('Employee', EmployeeSchema);
var db = mongoose.connection;
var dbUrl = 'mongodb://iagoabuu:timelapse11' + encodeURIComponent('$') + '@ds012538.mlab.com:12538/dbhrp';


console.log('db url is - ' + dbUrl);

var TeamSchema = new Schema({
name: {
type: String,
required: true
}
}, { collection : 'teams' });

var Team = mongoose.model('Team', TeamSchema);
db.on('error', function () {
console.log('there was an error communicating with the database');
});




function retrieveEmployee (callback) {
Employee.findOne({
'name.first': 'Thomas'
}).populate('team').exec(function (error, result) {
if (error) {
return console.log(error);
} else {
console.log('*** Single Employee Result ***');
console.dir(result);
callback(null, result);
}
});
}




mongoose.connect(dbUrl, function (err) {
if (err) {
return console.log('there was a problem connecting to the database!' + err);
}
console.log('connected!');


retrieveEmployee(function (err, result) {
if (err) {
console.error(err);
} else {
console.info('database activity complete')
}
db.close();
process.exit();
});


});


==============
single-emp-1.js

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

var EmployeeSchema = new Schema({
name: {
first: {
type: String,
required: true
},
last: {
type: String,
required: true
}
},
team: {
type: Schema.Types.ObjectId,
ref: 'Team'
},
image: {
type: String,
default: 'images/user.png'
},
address: {
lines: {
type: [String]
},
postal: {
type: String
}
}
}, { collection : 'employees' });

var Employee = mongoose.model('Employee', EmployeeSchema);
var db = mongoose.connection;
var dbUrl = 'mongodb://iagoabuu:timelapse11' + encodeURIComponent('$') + '@ds012538.mlab.com:12538/dbhrp';


console.log('db url is - ' + dbUrl);

var TeamSchema = new Schema({
name: {
type: String,
required: true
}
}, { collection : 'teams' });

var Team = mongoose.model('Team', TeamSchema);
db.on('error', function () {
console.log('there was an error communicating with the database');
});




function retrieveEmployee (callback) {
Employee.findOne({
'name.first': 'Thomas'
}).populate('team').exec(function (error, result) {
if (error) {
return console.log(error);
} else {
console.log('*** Single Employee Result ***');
console.dir(result.name.last);
callback(null, result);
}
});
}




mongoose.connect(dbUrl, function (err) {
if (err) {
return console.log('there was a problem connecting to the database!' + err);
}
console.log('connected!');


retrieveEmployee(function (err, result) {
if (err) {
console.error(err);
} else {
console.info('database activity complete')
}
db.close();
process.exit();
});


});


==============
single-emp-2.js


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

var EmployeeSchema = new Schema({
name: {
first: {
type: String,
required: true
},
last: {
type: String,
required: true
}
},
team: {
type: Schema.Types.ObjectId,
ref: 'Team'
},
image: {
type: String,
default: 'images/user.png'
},
address: {
lines: {
type: [String]
},
postal: {
type: String
}
}
}, { collection : 'employees' });

var Employee = mongoose.model('Employee', EmployeeSchema);
var db = mongoose.connection;
var dbUrl = 'mongodb://iagoabuu:timelapse11' + encodeURIComponent('$') + '@ds012538.mlab.com:12538/dbhrp';


console.log('db url is - ' + dbUrl);

var TeamSchema = new Schema({
name: {
type: String,
required: true
}
}, { collection : 'teams' });

var Team = mongoose.model('Team', TeamSchema);
db.on('error', function () {
console.log('there was an error communicating with the database');
});




function retrieveEmployee (callback) {
Employee.findOne({
'name.first': 'Thomas'
}).populate('team').exec(function (error, result) {
if (error) {
return console.log(error);
} else {
console.log('*** Single Employee Result ***');
console.dir(result.team._doc.name);
callback(null, result);
}
});
}




mongoose.connect(dbUrl, function (err) {
if (err) {
return console.log('there was a problem connecting to the database!' + err);
}
console.log('connected!');


retrieveEmployee(function (err, result) {
if (err) {
console.error(err);
} else {
console.info('database activity complete')
}
db.close();
process.exit();
});


});

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.