'get undefined when requiring data from another file which queries mongodb collection
in the export.js file, everything works fine, I can consoleLog the correct collection queried from mongodb, but in the import.js file, the collection is consoleLogged immediately and is undefined, I don't know what's wrong
//export.js
module.exports = client.connect(async () => {
const db = client.db("database");
const collection = await db.collection("collection").find().toArray();
client.close();
console.log(collection);
return collection;
});
//require.js
const collection = require("./export");
console.log(collection);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
