LAMP
|
vs |
MEAN
|
![]() |
MongoDB NoSQL Database Express Node.js web app framework Angular SPA framework Node.js Platform for building server-side apps |
Mongo |
|
Node |
|
Angular |
|
CRUD | HTTP | SQL | MONGO |
Create | POST | INSERT | db.collection.insert() |
Read | GET | SELECT | db.collection.find() |
Update | PUT | UPDATE | db.collection.update() |
Delete | DELETE | DELETE | db.collection.delete() |
Meta-model | Data Perspective |
Conceptual | Entities, Attributes, Relationships, Identifiers |
Logical | Tables, Columns, Primary and foreign keys |
Physical | Indexes, Table spaces |
SQL | Mongo |
database | database |
table | collection |
row | document |
column | field |
index | index |
joins |
embedded documents
and linking
|
primary key | primary key |
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var blogSchema = new Schema({
title: String,
author: String,
body: String,
comments: [{ body: String, date: Date }],
date: { type: Date, default: Date.now },
hidden: Boolean,
meta: {
votes: Number,
favs: Number
}
});
var Blog = mongoose.model('Blog', blogSchema);
# Create the folder for your project
mkdir exp_test ; cd exp_test
# Create the server.js file
touch server.js
# Create package.json using npm init
npm init
# Finally use npm to install express
npm install --save express
// we need to handle http requests
var http = require('http');
// this function creates our server and starts listening to port 1337
http.createServer(function (req, res) {
// send plain text content
res.writeHead(200, {'Content-Type': 'text/plain'});
// print out Hello World
res.end('Hello World\n');}).listen(1337, '127.0.0.1');
// display message in the console
console.log('Server running at http://127.0.0.1:1337/');
// load the express module
var express = require('express');
// declare our app
var app = express();
// handle get requests at the / route
app.get('/', function(req, res){
res.send('Hello World\n'); // some voodoo magic
});
// listen for requests
var server = app.listen(1337, function() {
console.log('Listening on port %d', server.address().port);
});
/api/users - collection
/api/users/types - collection controller
/api/users/john - document
/api/users/john/comments - document controller