diff --git a/.env b/.env index ca905fe..1849968 100644 --- a/.env +++ b/.env @@ -3,4 +3,4 @@ FACEBOOK_VALIDATION_TOKEN=58eb669e-9a3c-4940-ba2a-45833ed28ff1 FACEBOOK_PAGE_ACCESS_TOKEN=EAAbiTcER2bkBAConk7qPEvqaIRT0MucHZBCDVxZBqZB14qUofVZCnryAbWxXn9atzofmG5jm98y1iZB5RIMxagxCL6ar0QGS8JzqHEoGTlX9vYTiHMfyyUwFDz7ORZCsSzjzQZCsOOyvCGdgTJva9RvHMNmAP0H7eQ4C2eTmOohGAZDZD TELEGRAM_ACCESS_TOKEN=338652885:AAFkX3S6s2GcRbHOkZ5WHAllBhbrf40FPiI MONGO_DB_TOKEN=H4411Admin:tNXjN5Au8wXYi0IV -RECAST_TOKEN=9e3038ff6198a787f1fff329b0b66dab \ No newline at end of file +RECAST_TOKEN=9e3038ff6198a787f1fff329b0b66dab diff --git a/AslanDBConnector.js b/AslanDBConnector.js index 36a9d2e..5529598 100644 --- a/AslanDBConnector.js +++ b/AslanDBConnector.js @@ -34,7 +34,7 @@ exports.getData = function(table, query, callback) { }); } -exports.LoadJSonData = function(filePath) { +exports.loadJSonData = function(filePath) { // Connexion au serveur avec la méthode connect mongoClient.connect(url, function (err, db) { try{ @@ -58,3 +58,27 @@ exports.LoadJSonData = function(filePath) { } +exports.replaceDocument = function (filePath) { + // Connexion au serveur avec la méthode connect + mongoClient.connect(url, function (err, db) { + try { + if (err) { + return console.log('Connection failed', err); + } + fs.readFile(filePath, 'utf8', function (err, data) { + if (err) throw err; + + var json = JSON.parse(data); + + db.collection(GrandLyonCollection).findOneAndReplace({ "doc_id": json.doc_id}, json, function (err, doc) { + console.log("Load done"); + if (err) throw err; + }); + }); + } catch (error) { + console.log(error); + } + }); +} + + diff --git a/data/dataTest.json b/data/dataTest.json new file mode 100644 index 0000000..7e8d8db --- /dev/null +++ b/data/dataTest.json @@ -0,0 +1,40 @@ +{ + "features": [ + + { + "entity":{ + + "name": "Jackson", + "type": "person", + "job": "CEO" + } + }, + { + "entity":{ + + "name": "Edward", + "type": "person", + "job": "CTO" + } + }, + { + "entity":{ + + "name": "Alfred", + "type": "person", + "job": "Lead Architect" + } + }, + { + "entity":{ + + "name": "Aslan", + "type": "person", + "job": "Intern" + } + } + + + ], + "doc_id": "data test" +} diff --git a/data/dataTestUpdated.json b/data/dataTestUpdated.json new file mode 100644 index 0000000..1ee53d7 --- /dev/null +++ b/data/dataTestUpdated.json @@ -0,0 +1,48 @@ +{ + "features": [ + + { + "entity":{ + + "name": "Albert", + "type": "person", + "job": "CEO" + } + }, + { + "entity":{ + + "name": "Francis", + "type": "person", + "job": "CTO" + } + }, + { + "entity":{ + + "name": "Alfred", + "type": "droid", + "job": "Lead Architect" + } + }, + { + "entity":{ + + "name": "Aslan", + "type": "lion", + "job": "mascot" + } + }, + { + "entity":{ + + "name": "Boris", + "type": "person", + "job": "business accountant" + } + } + + + ], + "doc_id": "data test" +} diff --git a/loadMongoDB.js b/loadMongoDB.js index 69c3fdd..45ecc8a 100644 --- a/loadMongoDB.js +++ b/loadMongoDB.js @@ -1,10 +1,3 @@ -/* -* index.js -* Point d'entrée de l'application -* version 0.1.1 -* Tiré du tuto http://www.supinfo.com/articles/single/3246-realisez-bot-facebook-messenger-nodejs -* https://developers.facebook.com/docs/messenger-platform/guides/quick-start/ -*/ 'use strict'; const aslanDB = require('./AslanDBConnector'); @@ -13,7 +6,7 @@ process.argv.forEach(function (val, index, array) { if(index > 1) { - aslanDB.LoadJSonData(array[index]); + aslanDB.loadJSonData(array[index]); } }); diff --git a/updateMongoDB.js b/updateMongoDB.js new file mode 100644 index 0000000..095d00d --- /dev/null +++ b/updateMongoDB.js @@ -0,0 +1,12 @@ +'use strict'; + +const aslanDB = require('./AslanDBConnector'); + +process.argv.forEach(function (val, index, array) { + + if(index > 1) + { + aslanDB.replaceDocument(array[index]); + } + +});