My bot's database keeps just...disappearing?
Hello!
I'm a front-end developer that decided to try my hand at discord bots. I've made a few chat bots before so I'm relatively familiar with command processing and the like, but databases were never my specialty, working with the frontend mainly.
I decided to go Mongo for reliability/stability on the VPS I'm running the bot on, but for some reason every now and again in the past few days of testing, the entire database just...poofs.
I am 0% confident in my entire database connection, so if anybody wanted to give it a look over and tell me if I'm missing something obvious or doing something incredibly dumb, I'd be eternally grateful.
The bot is open source and hosted at https://github.com/12px/chandler
The relevant database files are plugins/state.js and plugins/state.model.js
About the bot
Chandler is very simple and only does a few things, basic message management and the like. However, I'm trying to implement a timezone tracking feature that keeps track of what time it is for users in the server. This feature actually works great, you can do >time and Chandler tells you what time it is for everyone who set a timezone.
However, when the database of user timezones keeps randomly resetting...
And it's the entire database, it seems, not just the zone collection. I also lose all other custom settings I'm saving.
Posted Jul 15, 2019, 2:31 PM UTC
You might wanna try using a different database system like SQLite3 or PostgreSQL. Mongo isn’t all that webscale and can become slow when working with larger projects, at least in my experience. That said if you want to use Mongo, go ahead. I’ve had plenty of odd tools that people try and steer me away from.
As for your initial problem, I’ll take a look and see what’s the issue.
As I’m looking through I’m noticing a bunch of things,
==) to check one value against another. This is generally frowned upon because it can produce some pretty wonky results if not used correctly. I would switch all of those to the strict equality operator (===).When does this problem occur? After a restart? At random intervals?
I really wanted to go no SQL ideally, but I'm not entirely set on Mongo. I was actually considering lowdb beforehand, but I can't imagine that scaling well either.
Right now, I have a database for every guild, and collections, but someone suggested I have a singular database and collections instead, just adding guildID to all my data. I'm not sure if that would work but I'm willing to give it a shot, I suppose.
Also not sure how that would affect my database just disappearing.
Thanks for taking the time to help though! I appreciate it.