-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_actions_test.js
More file actions
50 lines (42 loc) · 1.42 KB
/
db_actions_test.js
File metadata and controls
50 lines (42 loc) · 1.42 KB
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
/**
* transformers
* Created by nsubbot on 28.08.17.
* All rights reserved by Nikita Subbot ©
*/
let mongoose = require("./libs/mongoose");
mongoose.set("debug", true);
let async = require("async");
async.series([
openConnection,
dropDatabase,
requireModels,
createTransformers
], function (err) {
console.log(arguments);
mongoose.disconnect();
process.exit(err ? 255 : 0);
});
function openConnection(callback) {
mongoose.connection.on('open', callback);
}
function dropDatabase(callback) {
let db = mongoose.connection.db;
db.dropDatabase(callback);
}
function requireModels(callback) {
require('./models/transformer');
async.each(Object.keys(mongoose.models), function (modelName, callback) {
mongoose.models[modelName].ensureIndexes(callback);
}, callback);
}
function createTransformers(callback) {
let transformers = [
{ owner: "Niks", name: "Prime", homePlanet: "Cibertrone", health: "200", attack: "10", type: "Autobot" },
{ owner: "Niks", name: "Megatrone", homePlanet: "Cibertrone", health: "120", attack: "10", type: "Decepticon" },
{ owner: "Niks", name: "JZ", homePlanet: "Cibertrone", health: "100", attack: "10", type: "Autobot" },
];
async.each(transformers, function (transformersData, callback) {
let trans = new mongoose.models.Transformer(transformersData);
trans.save(callback);
}, callback);
}