-
Notifications
You must be signed in to change notification settings - Fork 2
/
example.js
58 lines (50 loc) · 1.1 KB
/
example.js
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
57
58
var mongoose = require('./lib/index');
var Schema = mongoose.Schema;
var cradle = require('cradle');
mongoose.connect('http://localhost', 5984, {
cache: false,
raw: false
});
var AccountSchema = new Schema({
slug: {
type: String,
unique: true,
lowercase: true,
trim: true,
match: /^[a-z0-9-]+$/
},
email: {
type: String,
lowercase: true,
trim: true,
match: /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
},
hash: {
type: String
},
apiKey: {
type: String,
unique: true
},
roles: {
type: [String],
required: true,
'default': ['lead']
}
}, {
collection: 'testy-mcgee'
});
module.exports = Account = mongoose.model('Account', AccountSchema);
var account = new Account({
slug: 'hello',
email: '[email protected]',
roles: ['lead']
});
account.save(function (err) {
account.roles.push('admin');
account.save(function (err) {
Account.findById(account._id, function (err, res) {
console.log(err || res);
});
});
});