whether the operation is successful. This functionality needs to be implemented by adding the third parameter {safe:ture}, i.e. App.users.insert (Req.body.user, {safe:ture}, function () {...}). This will result in the successful reading of the results.
3.connect-connect Store Not defined
Copy Code code as follows:
Mongostore = require (' Connect-mongo ')
App.use (Express.session ({
Secret:settings.cookieSecret,
Store:new
/cobbler # system installation image directory/var/www/cobbler/ks_mirror # list of imported system images/ var/www/cobbler/images # imported system image Startup file/var/www/cobbler/repo_mirror # yum source storage directory/var/log/cobbler # log directory/var/log /cobbler/install. log # Client System Installation log/var/log/cobbler. log # cobbler log3. Initial cobbler configuration 1. Start the cobbler Service
Cobbler depends on the httpd service, so you must first start httpd; otherwise, an
operations do not return their results to determine whether the operation is successful. You need to add the third parameter {safe: ture} to implement this function, that is, the app. users. insert (req. body. user, {safe: ture}, function (){......}). In this way, the result is read successfully.
3. undefined store appears in connect-connect
Copy codeThe Code is as follows:External Store = require ('connect-mongo ')App. use (express. session ({Secret: settings. cookieSecret,Store: new External
the operation was successful. This function needs to be implemented by adding the third parameter {safe:ture}, which is App.users.insert (Req.body.user, {safe:ture}, function () {...}). This will result in a successful read.3.connect-connect an undefined store appears1 mongostore = require (' Connect-mongo ')23app.use (express.session ({ 4 Secret:settings.cookieSecret,5 Store:new mongostore ({6
'),
2 Db = require (' MongoDB '). Db,
3 Connection = require (' MongoDB '). Connection,
4 Server = require (' MongoDB '). Server;
5 Module.exports = new Db (settings.db, New Server (Settings.host, Connection.default_port, {}), {safe:true});
When referencing the settings module, if you follow the book:
1 var settings = require (' ... /settings ');
will appear:
This is because the latest Express version requires this module to be referenced in this way:
1 var settings = requir
1 adding dependencies"MongoDB": "1.4.15", "express-session": "1.9.1", "Connect-mongo": "0.4.1", "Connect-flash": "0.1.1"Where Connect-flash is used to record the login session (I do not know if it is right, because it is not carefully used)App.jsvar express = require (' Express '), var path = require (' path '), var favicon = require (' Serve-favicon '); var logger = require (' m Organ '), var cookieparser = require (' Cookie-parser '), var bodyparser = require (' Body-parser '), var routes = re
unpredictable, but when Google, a friend did a very good answer:
Http://www.cnblogs.com/yumianhu/p/3709558.html
That is, in EXPRESS4 we need to install the Express-session package ourselves and then add the reference:
var session = require (' express-session ');
The original database reference also needs to be changed to:
var Mongostore = require (' Connect-mongo ') (session);
and the code:
App.use (Express.session ({
Secret:settings.cookie_s
(1) Nodejs: Error Registering login sessionWorkaround:change var Mongostore = require (Connect-mongo ') to var mongostore = require (Connect-mongo ') (Express) in App.js;(2) Error connecting to database solution when connecting to MongoDB databaseIn this case your own MongoDB database is not installed wellWorkaround:A. Download the installation database on the official websiteB. Create a new folder inside t
This article mainly introduces the login registration function of Node + Express + MongoDB. If you need it, refer to this article to introduce the login registration function of Node + Express + MongoDB, for more information, see
Inject MongoDB Dependencies
var mongoose = require("mongoose");
Because form processing is required, bodyParser middleware is required.
The bodyParser module parses files and formats the data in the form.
var bodyParser = require("body-parser"); app.use(bodyParser.js
://www.cnblogs.com/yumianhu/p/3709558.html
In other words, in express4, We need to install the express-session package by ourselves, and then add reference:
var session = require('express-session');
The original database reference also needs to be changed:
var MongoStore = require('connect-mongo')(session);
And the code:
app.use(express.session({ secret: settings.cookie_secret, store:new MongoStore
', {title: 'helpers '});});
You need to change it to var util = require ('util'); app. locals ({inspect: function (obj) {return util. inspect (obj, true) ;}}); app. use (function (req, res, next) {res. locals. headers = req. headers; next () ;}); app. get ('/helper', function (req, res) {res. render ('helper ', {title: 'helpers '});});
Note that the above Code should be placed in front of app. use (app. router.
Question 4:Express3. * The layout method is not supported, so you must change it to
MongoStore = require('connect-mongo')(session);
And the code:
app.use(express.session({ secret: settings.cookie_secret, store:new MongoStore({ db: settings.db })}));
You need to rewrite it:
app.use(session({ secret: settings.cookie_secret, store: newMongoStore({ db : settings.db, }) }));
For view interaction mentioned in the book, the original code is:
app.dynamicHelpers({ user
= require('mongodb').Db,
Connection = require('mongodb').Connection,
Server = require('mongodb').Server;
module.exports = new Db(settings.db, new Server(settings.host, Connection.DEFAULT_PORT, {}), {safe: true});
When referencing the settings module, if you follow the book:
var settings = require('../settings');
will appear:
This is because the latest Express version requires this module to be referenced in this way:
var settings = require('./settings');
But after solvi
'),
2 Db = require (' MongoDB '). Db,
3 Connection = require (' MongoDB '). Connection,
4 Server = require (' MongoDB '). Server;
5 Module.exports = new Db (settings.db, New Server (Settings.host, Connection.default_port, {}), {safe:true});
When referencing the settings module, if you follow the book:
1 var settings = require (' ... /settings ');
will appear:
This is because the latest Express version requires this module to be referenced in this way:
1 var settings = requir
DB is the name of the database, host is the address of the database, port is the port number of the database, Cookiesecret for Cookie encryption is not related to the database, we leave it for later use.Then create the Models folder and create the Db.js in lime, as followsvar settings = require ('.. /settings '), = require (' MongoDB '). Db, = require (' MongoDB '). Connection, = require (' MongoDB 'newnewtrue});Session SupportGet Connect-mongo and express-session modules, add in Packa
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.