-
Notifications
You must be signed in to change notification settings - Fork 0
/
import.js
32 lines (27 loc) · 936 Bytes
/
import.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
//displaying time on console
var date = require('date-and-time')
var now = new Date();
date.format(now, 'HH:mm')
console.log(now)
//reading JSON
const jf = require('jsonfile')
var aux = require("./functions/func-aux.js")
var myMethList = jf.readFileSync(__dirname + "/models/methods.json")
console.log("Method List loaded: " + myMethList.length + "methods")
//setting database
const MongoClient = require('mongodb').MongoClient
MongoClient.connect('mongodb://jcr:[email protected]:49711/guitar-methods',
(err, database) => {
if (!err) {
db = database
db.collection('gmethods')
myMethList.forEach(function(element) {
db.collection('gmethods').save(element, (err, result) => {
if (!err) console.log(element + " was saved!")
else console.log("Error: saving data...")
})
}, this);
}
else
console.log("Connection to Mongo server unsuccessful.")
})