Skip to content

Commit

Permalink
Tested the MongoDB scripts and fixed them
Browse files Browse the repository at this point in the history
  • Loading branch information
iamakshat01 committed Apr 20, 2021
1 parent e958dbf commit 59b3dae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions demos/database/MongoDBCRUD.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let P = Promise.resolve("sheetjs");

/* Connect to mongodb server */
P = P.then(async () => {
const client = await MongoClient.connect(url);
const client = await MongoClient.connect(url,{ useUnifiedTopology: true });
return [client];
});

Expand Down Expand Up @@ -49,14 +49,15 @@ P = P.then(async ([client, pres, fmts]) => {
});

/* Read the new file and dump all of the data */
P = P.then(() => {
P = P.then(([client]) => {
const wb = XLSX.readFile('mongocrud.xlsx');
wb.SheetNames.forEach((n,i) => {
console.log(`Sheet #${i+1}: ${n}`);
const ws = wb.Sheets[n];
console.log(XLSX.utils.sheet_to_csv(ws));
});
return [client];
});

/* Close connection */
P.then(async ([client]) => { client.close(); });
P.then(async ([client]) => { client.close(); });
2 changes: 1 addition & 1 deletion demos/database/MongoDBTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let P = Promise.resolve("sheetjs");

/* Connect to mongodb server and initialize collection */
P = P.then(async () => {
const client = await MongoClient.connect(url);
const client = await MongoClient.connect(url,{ useUnifiedTopology: true });
const db = client.db(db_name);
try { await db.collection('wb').drop(); } catch(e) {}
const coll = db.collection('wb');
Expand Down
5 changes: 2 additions & 3 deletions demos/database/SheetJSMongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
var XLSX = require("xlsx");

async function book_append_mongo(wb, coll, name) {
const aoo = await coll.find({}).toArray();
aoo.forEach((x) => delete x._id);
const aoo = await coll.find({}, {projection:{_id:0}}).toArray();
const ws = XLSX.utils.json_to_sheet(aoo);
XLSX.utils.book_append_sheet(wb, ws, name);
return ws;
}

module.exports = {
book_append_mongo
};
};

0 comments on commit 59b3dae

Please sign in to comment.