I have a script which suppose to pull data from mongo and save data in JSON, CSV or EXCELL sheet. Currently, i am able to get data but during saving i am using the following script.
import fs from "fs"
const cursor = db.getCollection("users").find({}, { name: 1, email:1 ,
phone:1});
let users = [];
while (cursor.hasNext()) {
const user = cursor.next();
users.push({name: user.name, email:user.email, phone:user.phone})
}
//print(JSON.stringify(users))
fs.writeFile ("test.json", JSON.stringify(users), function(err) {
if (err) throw err;
console.log('complete');
}
);
gives me this error
uncaught exception: SyntaxError: import declarations may only appear at the top level of a module :
I have tried a couple of solutions from here link1 link2
but non of them are working. Can anyone suggest me a solution