I am using nedb as a database for a small discord bot I have created.
Downloaded via npm install nedb --save, and set up in the main file with:
const { callbackify } = require('util');
var db = new Datastore('botDB.db');
db.loadDatabase();
Additionally, I am using these search functions to implement an initial list within the database and search for people within the database.
function findPlayer(params, callback)
{
db.find({name:params}, (err,docs)=>
{
callback(docs);
});
}
findPlayer('list', function(users){
if (!users[0])
{
let players = {
name:'list',
list:[]
};
db.insert(players,function(err,newDoc){});
}
})
Finally, I create a command to add someone to the database. With the following code being placed as a callback within a findPlayer function.
let updateData = {
name:key,
display:args[0],
socialCredit: 0,
games: []
}
db.insert(updateData,function(err,newDoc){
message.reply("Added you to the database.")
console.log(err)
});
findInList(key, function(users){
if(!users[0])
{
db.update({name:'list'},{$push:{list:key}},{},function(){});
}
})
When i run the code, and type the command, the console logs this error.
RangeError: Maximum call stack size exceeded
at Object.isArray (<anonymous>)
at deepCopy (C:\Users\ME\Desktop\Editing\Coding Projects\Discod Bot\node_modules\nedb\lib\model.js:120:12)
at C:\Users\ME\Desktop\Editing\Coding Projects\Discod Bot\node_modules\nedb\lib\model.js:130:18
at Array.forEach (<anonymous>)
at deepCopy (C:\Users\ME\Desktop\Editing\Coding Projects\Discod Bot\node_modules\nedb\lib\model.js:128:22)
at C:\Users\ME\Desktop\Editing\Coding Projects\Discod Bot\node_modules\nedb\lib\model.js:130:18
at Array.forEach (<anonymous>)
at deepCopy (C:\Users\ME\Desktop\Editing\Coding Projects\Discod Bot\node_modules\nedb\lib\model.js:128:22)
at C:\Users\ME\Desktop\Editing\Coding Projects\Discod Bot\node_modules\nedb\lib\model.js:130:18
at Array.forEach (<anonymous>)
When researching this error, most results i have come accross have been using recursion of some form, and that the stack size is 1000 or something rediculous when i am implementing 1 object into an almost completely empty database. I have another command that is very similar that implements into the database correctly, and i cannot find a distinguishing factor between the two functions that would change how it works, they both have the same format.