forked from TeamRoan/Blacksmith-Post
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitemSeed.js
56 lines (40 loc) · 1.4 KB
/
itemSeed.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
var fs = require('fs');
var mongoose = require('mongoose');
mongoose.connect(process.env.MONGOLAB_URI || 'mongodb://localhost/blacksmith');
var db = mongoose.connection;
db.collection('items').drop();
//creates new collection of items with data loated in data.json
var docs = fs.readFile('predata.json', 'utf8', function (err, data) {
var items = db.collection('items');
console.log(data)
items.insert(JSON.parse(data), function (err, docs) {
items.count(function (err, count) {
console.log(count + "[" + data + "]");
db.close();
});
});
});
db.collection('transactions').drop();
//creates new collection of items with data loated in data.json
var docs = fs.readFile('transactiondata.json', 'utf8', function (err, data) {
var transactions = db.collection('transactions');
console.log(data)
transactions.insert(JSON.parse(data), function (err, docs) {
transactions.count(function (err, count) {
console.log(count + "[" + data + "]");
db.close();
});
});
});
db.collection('users').drop();
//creates new collection of items with data loated in data.json
var docs = fs.readFile('userdata.json', 'utf8', function (err, data) {
var users = db.collection('users');
console.log(data)
users.insert(JSON.parse(data), function (err, docs) {
users.count(function (err, count) {
console.log(count + "[" + data + "]");
db.close();
});
});
});