question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing the example of the bot with mongodb, I’m trying to use quickmongo to use the mongodb database but I’m finding a problem with the package

in the index I add this in place of the quick.db application

const { Database } = require("quickmongo");
const db = new Database("mongodb+srv://giveaway:pass@cluster0.phlie.gcp.mongodb.net/giveaway?retryWrites=true&w=majority");

and I get this error at the terminal

(node:2412) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of null
    at GiveawayManagerWithOwnDatabase._init (C:\Users\Italo\Desktop\GiveBotV12\node_modules\discord-giveaways\src\Manager.js:392:22)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:2412) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2412) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
misa-codercommented, Aug 4, 2020
3reactions
skdhgcommented, Aug 4, 2020

I’ve tested the code just now on my bot and it worked perfectly. Here is the extended GiveawaysManager class:

const { GiveawaysManager } = require("discord-giveaways");
const { Database } = require("quickmongo");
const db = new Database("mongodb://localhost/giveaways");

db.once("ready", async () => {
    if (await db.get("giveaways") === null) await db.set("giveaways", []);
});

class GiveawayManager extends GiveawaysManager {

    async getAllGiveaways() {
        return await db.get("giveaways");
    }

    async saveGiveaway(messageID, giveawayData) {
        await db.push("giveaways", giveawayData);
        return true;
    }

    async editGiveaway(messageID, giveawayData) {
        const giveaways = await db.get("giveaways");
        const newGiveawaysArray = giveaways.filter((giveaway) => giveaway.messageID !== messageID);
        newGiveawaysArray.push(giveawayData);
        await db.set("giveaways", newGiveawaysArray);
        return true;
    }

    async deleteGiveaway(messageID) {
        const data = await db.get("giveaways");
        const newGiveawaysArray = data.filter((giveaway) => giveaway.messageID !== messageID);
        await db.set("giveaways", newGiveawaysArray);
        return true;
    }

}

module.exports = GiveawayManager;
Read more comments on GitHub >

github_iconTop Results From Across the Web

@turph/quickmongo - npm
A simple database using mongodb atlas. Latest version: 1.4.5, last published: a year ago. Start using @turph/quickmongo in your project by ...
Read more >
Mongoose detect database not ready - Stack Overflow
I would recommend using the open and error events to check if you can connect to the database. This is a simple example...
Read more >
Mongodb localhost connection - Drivers & ODMs
I am stuck why is the localhost:27017/example in UI saying still error as. It looks like you are trying to access MongoDB over...
Read more >
[Solved]-How to delete document by _id using quickmongo ...
To delete by _id, use remove() in MongoDB. Following is the syntax − db.yourCollectionName.remove({_id:yourObjectId});.
Read more >
quickmongo - NPM Package File explorer - Socket - Socket.dev
Start using Socket to analyze quickmongo and its 3 dependencies to secure your app from ... Error trying to load file: Maximum number...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found