8
8
// There are no duplication checks in place. Please only run this script once.
9
9
// ** IMPORTANT **
10
10
11
- var Nedb = require ( 'nedb' ) ;
12
- var mongodb = require ( 'mongodb' ) ;
13
- var async = require ( 'async' ) ;
14
- var path = require ( 'path' ) ;
15
- var common = require ( '../routes/common' ) ;
16
- var config = common . read_config ( ) ;
17
- var ndb ;
11
+ const Nedb = require ( 'nedb' ) ;
12
+ const mongodb = require ( 'mongodb' ) ;
13
+ const async = require ( 'async' ) ;
14
+ const path = require ( 'path' ) ;
15
+ const common = require ( '../routes/common' ) ;
16
+ const config = common . read_config ( ) ;
17
+ let ndb ;
18
18
19
19
// check for DB config
20
20
if ( ! config . settings . database . connection_string ) {
@@ -23,18 +23,18 @@ if(!config.settings.database.connection_string){
23
23
}
24
24
25
25
// Connect to the MongoDB database
26
- mongodb . connect ( config . settings . database . connection_string , { } , function ( err , mdb ) {
26
+ mongodb . connect ( config . settings . database . connection_string , { } , ( err , mdb ) => {
27
27
if ( err ) {
28
- console . log ( " Couldn't connect to the Mongo database" ) ;
28
+ console . log ( ' Couldn\ 't connect to the Mongo database' ) ;
29
29
console . log ( err ) ;
30
30
process . exit ( 1 ) ;
31
31
}
32
32
33
33
console . log ( 'Connected to: ' + config . settings . database . connection_string ) ;
34
34
console . log ( '' ) ;
35
35
36
- insertKB ( mdb , function ( KBerr , report ) {
37
- insertUsers ( mdb , function ( Usererr , report ) {
36
+ insertKB ( mdb , ( KBerr , report ) => {
37
+ insertUsers ( mdb , ( Usererr , report ) => {
38
38
if ( KBerr || Usererr ) {
39
39
console . log ( 'There was an error upgrading to MongoDB. Check the console output' ) ;
40
40
} else {
@@ -46,17 +46,17 @@ mongodb.connect(config.settings.database.connection_string, {}, function(err, md
46
46
} ) ;
47
47
48
48
function insertKB ( db , callback ) {
49
- var collection = db . collection ( 'kb' ) ;
49
+ const collection = db . collection ( 'kb' ) ;
50
50
console . log ( path . join ( __dirname , 'kb.db' ) ) ;
51
51
ndb = new Nedb ( path . join ( __dirname , 'kb.db' ) ) ;
52
- ndb . loadDatabase ( function ( err ) {
52
+ ndb . loadDatabase ( ( err ) => {
53
53
if ( err ) {
54
54
console . error ( 'Error while loading the data from the NeDB database' ) ;
55
55
console . error ( err ) ;
56
56
process . exit ( 1 ) ;
57
57
}
58
58
59
- ndb . find ( { } , function ( err , docs ) {
59
+ ndb . find ( { } , ( err , docs ) => {
60
60
if ( docs . length === 0 ) {
61
61
console . error ( 'The NeDB database contains no data, no work required' ) ;
62
62
console . error ( 'You should probably check the NeDB datafile path though!' ) ;
@@ -66,7 +66,7 @@ function insertKB(db, callback){
66
66
}
67
67
68
68
console . log ( 'Inserting articles into MongoDB...' ) ;
69
- async . each ( docs , function ( doc , cb ) {
69
+ async . each ( docs , ( doc , cb ) => {
70
70
console . log ( 'Article inserted: ' + doc . kb_title ) ;
71
71
72
72
// check for permalink. If it is not set we set the old NeDB _id to the permalink to stop links from breaking.
@@ -77,8 +77,8 @@ function insertKB(db, callback){
77
77
// delete the old ID and let MongoDB generate new ones
78
78
delete doc . _id ;
79
79
80
- collection . insert ( doc , function ( err ) { return cb ( err ) ; } ) ;
81
- } , function ( err ) {
80
+ collection . insert ( doc , ( err ) => { return cb ( err ) ; } ) ;
81
+ } , ( err ) => {
82
82
if ( err ) {
83
83
console . log ( 'An error happened while inserting data' ) ;
84
84
callback ( err , null ) ;
@@ -93,16 +93,16 @@ function insertKB(db, callback){
93
93
} ;
94
94
95
95
function insertUsers ( db , callback ) {
96
- var collection = db . collection ( 'users' ) ;
96
+ const collection = db . collection ( 'users' ) ;
97
97
ndb = new Nedb ( path . join ( __dirname , 'users.db' ) ) ;
98
- ndb . loadDatabase ( function ( err ) {
98
+ ndb . loadDatabase ( ( err ) => {
99
99
if ( err ) {
100
100
console . error ( 'Error while loading the data from the NeDB database' ) ;
101
101
console . error ( err ) ;
102
102
process . exit ( 1 ) ;
103
103
}
104
104
105
- ndb . find ( { } , function ( err , docs ) {
105
+ ndb . find ( { } , ( err , docs ) => {
106
106
if ( docs . length === 0 ) {
107
107
console . error ( 'The NeDB database contains no data, no work required' ) ;
108
108
console . error ( 'You should probably check the NeDB datafile path though!' ) ;
@@ -112,14 +112,14 @@ function insertUsers(db, callback){
112
112
}
113
113
114
114
console . log ( 'Inserting users into MongoDB...' ) ;
115
- async . each ( docs , function ( doc , cb ) {
115
+ async . each ( docs , ( doc , cb ) => {
116
116
console . log ( 'User inserted: ' + doc . user_email ) ;
117
117
118
118
// delete the old ID and let MongoDB generate new ones
119
119
delete doc . _id ;
120
120
121
- collection . insert ( doc , function ( err ) { return cb ( err ) ; } ) ;
122
- } , function ( err ) {
121
+ collection . insert ( doc , ( err ) => { return cb ( err ) ; } ) ;
122
+ } , ( err ) => {
123
123
if ( err ) {
124
124
console . error ( 'An error happened while inserting user data' ) ;
125
125
callback ( err , null ) ;
@@ -132,5 +132,3 @@ function insertUsers(db, callback){
132
132
} ) ;
133
133
} ) ;
134
134
} ;
135
-
136
-
0 commit comments