-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDb.js
43 lines (35 loc) · 1.04 KB
/
createDb.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
var mongoose = require('libs/mongoose');
var async = require('async');
async.series([
open,
dropDatabase,
requireModels,
createUsers
], function(err) {
console.log(arguments);
mongoose.disconnect();
});
function open(callback) {
mongoose.connection.on('open', callback);
}
function dropDatabase(callback) {
var db = mongoose.connection.db;
db.dropDatabase(callback);
}
function requireModels(callback) {
require('models/user');
async.each(Object.keys(mongoose.models), function(modelName, callback) {
mongoose.models[modelName].ensureIndexes(callback);
}, callback);
}
function createUsers(callback) {
var users = [
{username: 'Вася', email: "vasya@test.com", password: 'supervasya'},
{username: 'Петя', email: "petya@test.com", password: '123'},
{username: 'admin', email: "admin", password: 'admin'}
];
async.each(users, function(userData, callback) {
var user = new mongoose.models.User(userData);
user.save(callback);
}, callback);
}