-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmongo-test.js
More file actions
56 lines (39 loc) · 895 Bytes
/
mongo-test.js
File metadata and controls
56 lines (39 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require.paths.unshift(__dirname + '/../../lib/');
/**
* Module dependencies.
*/
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
mongoose.connect('mongodb://localhost/mongochat');
/**
* Schema definition
*/
var UserSchema = new Schema({
nick : { type: String, index: true }
, date : { type: Date , 'default': function() {
return new Date();
}}
});
/**
* Pre hook.
*/
UserSchema.pre('save', function(next, done){
//emailAuthor(done); // some async function
console.log('about to save User');
next();
});
/**
* Define model.
*/
//mongoose.model('User', User);
// retrieve my model
var User = mongoose.model('User', UserSchema);
// create a blog post
var bob = new User({nick: 'Bob'});
// create a comment
//post.comments.push({ title: 'My comment' });
bob.save(function (err) {
if (!err) {
console.log('Success!');
}
});