|
Creado por James Drummond
hace más de 9 años
|
|
Notes from MEAN stack documentQuick Mongo commands: - mongo - starts mongo shell- db - names current database- show databases - list databases // save one user $ db.users.save({ name: 'Chris' }); // save multiple users $ db.users.save([{ name: 'Chris'}, { name: 'Holly' }]); // save one user $ db.users.save({ name: 'Chris' }); // save multiple users $ db.users.save([{ name: 'Chris'}, { name: 'Holly' }]); // remove all db.users.remove({}); // remove one db.users.remove({ name: 'Holly' }); Use Robomongo for GUI interface
Use Mongoose in node: // grab the packages we need var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/db_name'); package.json { "name": "node-api", "main": "server.js", "dependencies": { "morgan": "~1.5.0", // Loggin "express": "~4.10.3", "body-parser": "~1.9.3", // pull post content from http requests "mongoose": "~3.8.19", "bcrypt-nodejs": "0.0.3" // Hash passwords } }
app.use() See http://expressjs.com/api.html#app.useMounts the middleware function(s) at the path. If path is not specified, it defaults to “/”. Middleware is a bunch of functions that occur in order on the request. Middleware can: Execute any code. Make changes to the request and the response objects. End the request-response cycle. Call the next middleware in the stack. There are several levels of middleware: Application-level middleware - Bound to an instance of the Express application // use body parser so we can grab information from POST requests app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); Router-level middleware - Error-handling middleware Built-in middleware Third-party middleware
¿Quieres crear tus propios Apuntes gratis con GoConqr? Más información.