正在显示
6 个修改的文件
包含
33 行增加
和
32 行删除
1 | 1 | |
2 | 2 | // # home |
3 | 3 | |
4 | +var mongoose = require('mongoose') | |
4 | 5 | exports = module.exports = home |
5 | 6 | |
6 | 7 | function home(app, lib, modeluser) { |
... | ... | @@ -12,29 +13,12 @@ function home(app, lib, modeluser) { |
12 | 13 | |
13 | 14 | about: function(req, res, next) { |
14 | 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 | 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 | 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 | 15 | type: Email, |
16 | 16 | required: true, |
17 | 17 | unique: true |
18 | - } | |
18 | + }*/ | |
19 | + name: String | |
19 | 20 | }) |
20 | 21 | |
21 | 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); | |
\ No newline at end of file | ... | ... |
... | ... | @@ -34,10 +34,9 @@ |
34 | 34 | "electrolyte": "*", |
35 | 35 | "express-session": "~1.1.0", |
36 | 36 | "method-override": "~1.0.1", |
37 | - "static-favicon": "~2.0.0-alpha", | |
38 | 37 | "cookie-parser": "~1.1.0", |
39 | 38 | "errorhandler": "~1.0.1", |
40 | 39 | "body-parser": "~1.2.0", |
41 | - "serve-favicon": "^2.0.0" | |
40 | + "serve-favicon": "~2.0.0" | |
42 | 41 | } |
43 | 42 | } | ... | ... |
请
注册
或
登录
后发表评论