forked from snyk-labs/nodejs-goof
-
Notifications
You must be signed in to change notification settings - Fork 15
/
db.js
36 lines (29 loc) · 795 Bytes
/
db.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
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var Todo = new Schema({
content: Buffer,
updated_at: Date,
});
mongoose.model('Todo', Todo);
var User = new Schema({
username: String,
password: String,
});
mongoose.model('User', User);
var mongoUri = 'mongodb://localhost/express-todo';
if (process.env.MONGOLAB_URI) {
mongoUri = process.env.MONGOLAB_URI;
}
mongoose.connect(mongoUri);
User = mongoose.model('User');
User.find({ username: 'admin' }).exec(function (err, users) {
console.log(users);
if (users.length === 0) {
console.log('no admin');
new User({ username: 'admin', password: 'SuperSecretPassword' }).save(function (err, user, count) {
if (err) {
console.log('error saving admin user');
}
});
}
});