updating doc in NeDB making duplicates docs

26 Views Asked by At

I am writing a game website and I am trying to use NeDB to store variables to an account and instead of updating the variables in the document it makes duplicates of the document with the same ID.

database.update({ uname: username }, { $set: {"donutMaker": updateObject} }, { multi: `your }, function(err, numReplaced) {
            if (err) {
                console.error("Error updating document:", err);
                response.status(500).json({ error: 'Internal Server Error' });
                return;
            }
            
            console.log("Number of documents replaced:", numReplaced);

            // Send a response indicating the update was successful
            response.json({ success: true });
        });

here's what I get in the database.

{"uname":"USERNAME","password":"U2FsdGVkX19FKiMFomkoVultaXUgh9sVYzLA+d5ovJQ=","email":"U2FsdGVkX18YFeJyWDHdQLJnAEHLRXTDwv+c95CyYew=","_id":"c0h7VmY8nvXIPefy"}
{"uname":"USERNAME","password":"U2FsdGVkX19FKiMFomkoVultaXUgh9sVYzLA+d5ovJQ=","email":"U2FsdGVkX18YFeJyWDHdQLJnAEHLRXTDwv+c95CyYew=","_id":"c0h7VmY8nvXIPefy","donutMaker":{"highScore":0,"auto":0,"autoCost":100,"multi":0,"multiCost":100,"donut":1,"multiDonut":1}}
{"uname":"USERNAME","password":"U2FsdGVkX19FKiMFomkoVultaXUgh9sVYzLA+d5ovJQ=","email":"U2FsdGVkX18YFeJyWDHdQLJnAEHLRXTDwv+c95CyYew=","_id":"c0h7VmY8nvXIPefy","donutMaker":{"highScore":0,"auto":0,"autoCost":100,"multi":0,"multiCost":100,"donut":2,"multiDonut":1}}
{"uname":"USERNAME","password":"U2FsdGVkX19FKiMFomkoVultaXUgh9sVYzLA+d5ovJQ=","email":"U2FsdGVkX18YFeJyWDHdQLJnAEHLRXTDwv+c95CyYew=","_id":"c0h7VmY8nvXIPefy","donutMaker":{"highScore":0,"auto":0,"autoCost":100,"multi":0,"multiCost":100,"donut":3,"multiDonut":1}}
{"uname":"USERNAME","password":"U2FsdGVkX19FKiMFomkoVultaXUgh9sVYzLA+d5ovJQ=","email":"U2FsdGVkX18YFeJyWDHdQLJnAEHLRXTDwv+c95CyYew=","_id":"c0h7VmY8nvXIPefy","donutMaker":{"highScore":0,"auto":0,"autoCost":100,"multi":0,"multiCost":100,"donut":4,"multiDonut":1}}
0

There are 0 best solutions below