I’m trying to connect the databse (I’m new at this) and worked once but now won’t work again, some videos say that you have to start MongoDB service, but they do it from their Windows, how can I start it on glitch?
The manager module
const mongoose = require("mongoose");
const Mongo = {
Con: async function() {
await mongoose.connect("mongodb://localhost/Profiles", {
useNewUrlParser: true,
useUnifiedTopology: true
});
console.log("HERE")
return mongoose;
},
Profile: mongoose.model(
"Profile",
mongoose.Schema({
Id: String,
Name: String,
Lvl: Number,
Coins: Number,
XP: Number
})
)
};
module.exports = Mongo;
Test command to try it
const mongo = require("../mongo.js");
module.exports = {
name: "test",
async execute(Discord, client, message, args) {
console.log("First")
let con = await mongo.Con();
try {
let profile = new mongo.Profile({
Id: message.author.id,
Name: message.author.username,
Lvl: 5,
Coins: 100,
XP: 400
});
console.log(profile);
profile
.save()
.then(r => console.info(r + "R"))
.catch(e => console.error(e + "E"));
} finally {
con.connection.close();
}
}
};
And the result on console is this one (Personalized errors)
First
MongooseServerSelectionError in test command: connect ECONNREFUSED 127.0.0.1:27017