forked from wtabor/wdi-project-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeds.js
60 lines (52 loc) · 1.78 KB
/
seeds.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
59
60
var mongoose = require('mongoose');
// var Todo = require('./models/todo');
/////////
var User = require("./models/user")
var Prompt = require("./models/prompt")
var Story = require("./models/story")
mongoose.connect('mongodb://localhost/promptsDB');
// our script will not exit until we have disconnected from the db.
function quit() {
mongoose.disconnect();
console.log('\nQuitting!');
}
// a simple error handler
function handleError(err) {
console.log('ERROR:', err);
quit();
return err;
}
console.log('removing old data...');
Prompt.remove({})
.then(function() {
// console.log('old data removed');
console.log('creating some new prompts...');
// var groceries = new Todo({ title: 'groceries', completed: false });
// var feedTheCat = new Todo({ title: 'feed the cat', completed: true });
var romancePrompt1 = new Prompt({promptTheme: "romance", promptText: "romantic story prompt 1"})
var romancePrompt2 = new Prompt({promptTheme: "romance", promptText: "romantic story prompt 2"})
var scifiPrompt1 = new Prompt({promptTheme: "scifi", promptText: "scifi story prompt 1"})
var scifiPrompt2 = new Prompt({promptTheme: "scifi", promptText: "scifi story prompt 2"})
return Prompt.create([romancePrompt1, romancePrompt2, scifiPrompt1, scifiPrompt2]);
})
.then(function(savedPrompts) {
console.log('Just saved', savedPrompts.length, 'prompts.');
return Prompt.find({});
})
.then(function(allPrompts) {
console.log('Printing all prompts:');
allPrompts.forEach(function(prompt) {
console.log(prompt);
});
return Prompt.findOne({promptTheme: 'romance'});
})
.then(function(deleted) {
return Prompt.find({});
})
.then(function(allPrompts) {
console.log('Printing all prompts:');
allPrompts.forEach(function(prompt) {
console.log(prompt);
});
quit();
});