Hello,
I’m trying to run a script from a script.js
in which I use require() to import additional logic from another js script. Example of the issue I’m running into:
in script.js
I have the following:
const { updateFunc } = require("update.js"); const payload = {}; let updateResult = updateFunc()
in updateFunc
I do the following:
const collection = db.users
const users = collection.find({}).toArray()
users.forEach(......)
This would give me the following errors:
TypeError: collection.find(...).toArray is not a function
or
TypeError: users.forEach is not a function
If the script is written directly in script.js
it works flawlessly. Could someone please help me understand what I’m doing wrong here? My understanding is that I could achieve what I’m trying to do with require(), but it doesn’t seem to work.