Fundamental components of computer programs:
Stores and manipulates information
The database design involves choosing:
E/R Modelling is used for conceptual design
Represent objects or things of interest
Entities are drawn as a box
Attributes are facts, properties, or details of an entity.
Represented a few different ways.
Relationships are an association between two or more entities.
An entity can participate in three types of relationships
Relationships are links between two entities
We can split a many to many relationship into two one to many relationships. A new entity represents the N:N relationship.
Look at your data and indentify
A university consists of a number of departments. Each department offers several programs. A number of courses make up each program. Students enroll in a particular program and take courses towards the completion of that program. Each course is taught by a professor from the appropriate department, and each professor advices a group of students.
A university consists of a number of departments. Each department offers several programs. A number of courses make up each program. Students enroll in a particular program and take courses towards the completion of that program. Each course is taught by a professor from the appropriate department, and each professor advices a group of students.
Entities: department, program, course, professor, student
Complete ER Diagram
Submit screenshot of running server
You may need to set permissions
mongod
mongo
db.users.insert(
{
name :'peter',
email:'peter@mit.du',
age :'18'
}
)
Multiple documents make a collection
Enter a few documents into your collection. When you are done, list them using db.yourCollectionName.find()
db.collection.update()
db.users.update(
{ email: "peter@mit.edu" },
{
$set: { email: "parker@mit.edu" }
}
)
If multi is set to true, all matching documents are updated. Else, only one document is updated.
db.users.update(
{},
{$set: { city: "boston" }},
{ multi: true }
)
// removes all documents from a collection,
// but does not remove the indexes
db.collection.remove();
// drops the entire collection,
// including the indexes
db.collection.drop();
Remove documents in the users collection with email parker@mit.edu
db.users.remove(
{
email : "parker@mit.edu"
}
)
the find method retrieves documents from a collection
db.collection.find()
An empty query document selects all documents in the collection. Not specifying a query document has the same effect.
// empty query document
db.users.find( {} );
// no query document
db.users.find();
db.users.find()
db.users.find( { email : "peter@mit.edu" } );
// --- output ---
// { "_id" : ObjectId("123"),
// "name" : "peter",
// "email": "peter@mit.du",
// "age" : "18" }
Use $in to match field values. The statement below matches documents in the users collection where the name field is peter or clark. For more query operators, see http://docs.mongodb.org/
db.users.find( { name : { $in : ['peter','clark'] } } )
// --- output ---
// { "_id" : ObjectId("5d"), "name" : "peter",
// "email" : "peter@mit.du", "age" : "18" }
// { "_id" : ObjectId("57"), "name" : "clark",
// "email" : "clark@mit.du", "age" : "25" }
load('yourPath/bulk_insert.js')
// load file using - load('yourFile.js')
var data = [
{ name : 'dan', email : 'dan@mit.edu'},
{ name : 'bob', email : 'bob@mit.edu'},
{ name : 'lou', email : 'lou@mit.edu'},
{ name : 'meg', email : 'meg@mit.edu'},
{ name : 'amy', email : 'amy@mit.edu'},
{ name : 'liv', email : 'liv@mit.edu'},
];
var length = data.length;
for (var i = 0; i < length; i++) {
db.students.insert(data[i]);
}