正在显示
6 个修改的文件
包含
33 行增加
和
32 行删除
| 1 | 1 | ||
| 2 | // # home | 2 | // # home |
| 3 | 3 | ||
| 4 | +var mongoose = require('mongoose') | ||
| 4 | exports = module.exports = home | 5 | exports = module.exports = home |
| 5 | 6 | ||
| 6 | function home(app, lib, modeluser) { | 7 | function home(app, lib, modeluser) { |
| @@ -12,29 +13,12 @@ function home(app, lib, modeluser) { | @@ -12,29 +13,12 @@ function home(app, lib, modeluser) { | ||
| 12 | 13 | ||
| 13 | about: function(req, res, next) { | 14 | about: function(req, res, next) { |
| 14 | // save project data | 15 | // save project data |
| 15 | - var User = modeluser; | ||
| 16 | - | ||
| 17 | - console.log(User); | ||
| 18 | - | ||
| 19 | - /*var user = new User({ | ||
| 20 | - email: 'user@example.com', | ||
| 21 | - }); | ||
| 22 | -*/ | ||
| 23 | - var upsertData = User;//user.toObject(); | ||
| 24 | - delete upsertData._id; | ||
| 25 | - | ||
| 26 | - User.update({email: 'user@example.com'}, upsertData, {upsert: true}, function( err, project ) { | ||
| 27 | - | ||
| 28 | - if(err){ | ||
| 29 | - res.send(500, {message: 'Error saving project data'}); | ||
| 30 | - return console.error('Error creating project data'); | ||
| 31 | - } | ||
| 32 | - | ||
| 33 | - res.send(200, {message: 'success'}); | ||
| 34 | - | 16 | + var User = mongoose.model('User', modeluser); |
| 17 | + console.log(modeluser); | ||
| 18 | + User.create({name: 'john'}, function( err, project ) { | ||
| 19 | + res.send(200, 'Hello, this is Igloo.') | ||
| 35 | }); | 20 | }); |
| 36 | 21 | ||
| 37 | - res.send(200, 'Hello, this is Igloo.') | ||
| 38 | } | 22 | } |
| 39 | 23 | ||
| 40 | } | 24 | } |
| 1 | 1 | ||
| 2 | // # user | 2 | // # user |
| 3 | 3 | ||
| 4 | -var mongoose = require('mongoose') | ||
| 5 | -var common = require('./common') | 4 | +var mongoose = require('mongoose'), |
| 5 | + common = require('./common'), | ||
| 6 | + Schema = mongoose.Schema, | ||
| 7 | + mongooseTypes = require('mongoose-types') | ||
| 6 | 8 | ||
| 7 | -var Schema = mongoose.Schema | ||
| 8 | -var mongooseTypes = require('mongoose-types') | ||
| 9 | mongooseTypes.loadTypes(mongoose) | 9 | mongooseTypes.loadTypes(mongoose) |
| 10 | 10 | ||
| 11 | -var Email = mongoose.SchemaTypes.Email | 11 | +//var Email = mongoose.SchemaTypes.Email |
| 12 | 12 | ||
| 13 | -var User = module.exports = new Schema({ | ||
| 14 | - email: { | 13 | +var User = new Schema({ |
| 14 | + /*email: { | ||
| 15 | type: Email, | 15 | type: Email, |
| 16 | required: true, | 16 | required: true, |
| 17 | unique: true | 17 | unique: true |
| 18 | - } | 18 | + }*/ |
| 19 | + name: String | ||
| 19 | }) | 20 | }) |
| 20 | 21 | ||
| 21 | User.plugin(common) | 22 | User.plugin(common) |
| 23 | + | ||
| 24 | +module.exports = User; | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +var MUser = mongoose.model('User', User); | ||
| 28 | + | ||
| 29 | +var user = new MUser({ | ||
| 30 | + name: 'user@example.com', | ||
| 31 | +}); | ||
| 32 | + | ||
| 33 | +MUser.create({name: 'john'}, function( err, project ) { | ||
| 34 | + console.log(200, 'Hello, this is Igloo.') | ||
| 35 | +}); | ||
| 36 | + | ||
| 37 | +console.log(MUser.db); |
| @@ -16,6 +16,7 @@ module.exports = function(_config) { | @@ -16,6 +16,7 @@ module.exports = function(_config) { | ||
| 16 | exports['@singleton'] = true; | 16 | exports['@singleton'] = true; |
| 17 | 17 | ||
| 18 | function mongo(callback) { | 18 | function mongo(callback) { |
| 19 | + console.log(config.db); | ||
| 19 | var connection = mongoose.createConnection( | 20 | var connection = mongoose.createConnection( |
| 20 | config.db.host, | 21 | config.db.host, |
| 21 | config.db.dbname, | 22 | config.db.dbname, |
| @@ -34,10 +34,9 @@ | @@ -34,10 +34,9 @@ | ||
| 34 | "electrolyte": "*", | 34 | "electrolyte": "*", |
| 35 | "express-session": "~1.1.0", | 35 | "express-session": "~1.1.0", |
| 36 | "method-override": "~1.0.1", | 36 | "method-override": "~1.0.1", |
| 37 | - "static-favicon": "~2.0.0-alpha", | ||
| 38 | "cookie-parser": "~1.1.0", | 37 | "cookie-parser": "~1.1.0", |
| 39 | "errorhandler": "~1.0.1", | 38 | "errorhandler": "~1.0.1", |
| 40 | "body-parser": "~1.2.0", | 39 | "body-parser": "~1.2.0", |
| 41 | - "serve-favicon": "^2.0.0" | 40 | + "serve-favicon": "~2.0.0" |
| 42 | } | 41 | } |
| 43 | } | 42 | } |
| @@ -10,6 +10,7 @@ module.exports = schemas | @@ -10,6 +10,7 @@ module.exports = schemas | ||
| 10 | function schemas(lib, callback) { | 10 | function schemas(lib, callback) { |
| 11 | 11 | ||
| 12 | _.each(models, function(schema, name) { | 12 | _.each(models, function(schema, name) { |
| 13 | + console.log(name, '333'); | ||
| 13 | lib.db.model(name, schema) | 14 | lib.db.model(name, schema) |
| 14 | }) | 15 | }) |
| 15 | 16 |
请
注册
或
登录
后发表评论