I'm trying to fetch all the data from my collection called "users" and all i'm getting back is undefined.
In my folder and file named leaderboard/lb.js, and yes, my database is called collections:
const mongoose = require("mongoose");
let out = {};
mongoose.connect(`mongodb+srv://ramoth123:${process.env.MONGOPASS}@ramfish-bot-mgpji.mongodb.net/collections?retryWrites=true&w=majority`, { useNewUrlParser: true }, function(err, db) {
    if (err) throw err;
    //let dbo = db.db("collections");
    db.collection("users").find({ xp: Number }).toArray(function(err, result) {
      if (err) throw err;
      out.users = result;     
      db.close();
    });
});                             
function leaderboardUsersRaw() {
  return out.users
}
module.exports = leaderboardUsersRaw
In my database collection named "users"
In my server.js file:
app.get("/leaderboard", (req, res) => {
  const leaderboardFile = require("./leaderboard/lb.js")
  let users = leaderboardFile()
  console.log(users)
  res.send(users)
})
What am i doing wrong???
EDIT: Now it's working but after i load it 2 times, tf is this?
 
    