Skip to content

Commit

Permalink
updateMongoDB implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Papnix committed Apr 14, 2017
1 parent 8300913 commit a1f1d96
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
RECAST_TOKEN=9e3038ff6198a787f1fff329b0b66dab
26 changes: 25 additions & 1 deletion AslanDBConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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);
}
});
}


40 changes: 40 additions & 0 deletions data/dataTest.json
Original file line number Diff line number Diff line change
@@ -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"
}
48 changes: 48 additions & 0 deletions data/dataTestUpdated.json
Original file line number Diff line number Diff line change
@@ -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"
}
9 changes: 1 addition & 8 deletions loadMongoDB.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -13,7 +6,7 @@ process.argv.forEach(function (val, index, array) {

if(index > 1)
{
aslanDB.LoadJSonData(array[index]);
aslanDB.loadJSonData(array[index]);
}

});
12 changes: 12 additions & 0 deletions updateMongoDB.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const aslanDB = require('./AslanDBConnector');

process.argv.forEach(function (val, index, array) {

if(index > 1)
{
aslanDB.replaceDocument(array[index]);
}

});

0 comments on commit a1f1d96

Please sign in to comment.