diff --git a/demos/database/MongoDBCRUD.js b/demos/database/MongoDBCRUD.js index 951c4d2..495da6d 100644 --- a/demos/database/MongoDBCRUD.js +++ b/demos/database/MongoDBCRUD.js @@ -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]; }); @@ -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(); }); \ No newline at end of file diff --git a/demos/database/MongoDBTest.js b/demos/database/MongoDBTest.js index ad9b909..fa360ca 100644 --- a/demos/database/MongoDBTest.js +++ b/demos/database/MongoDBTest.js @@ -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'); diff --git a/demos/database/SheetJSMongo.js b/demos/database/SheetJSMongo.js index 23c78c7..08f6e29 100644 --- a/demos/database/SheetJSMongo.js +++ b/demos/database/SheetJSMongo.js @@ -3,8 +3,7 @@ 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; @@ -12,4 +11,4 @@ async function book_append_mongo(wb, coll, name) { module.exports = { book_append_mongo -}; +}; \ No newline at end of file