#MongoDB

7 messages · Page 1 of 1 (latest)

arctic dustBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
pulsar mica
export class DatabaseService {
    private Database;
    private reservationQueue: Booking[] = [];
    private isProcessingQueue: boolean = false;

    constructor(databaseId: string) {

        if (databaseId === process.env.GUILDSERVER_GODS) {
            this.Database = GODSDB;
        } else if (databaseId === process.env.GUILDSERVER_REFUGIA) {
            this.Database = REFUGIADB;
        } else {
            throw new Error(`Unknown database ID: ${databaseId}`);
        }
    }

    public async enqueueReservation(reservation: Booking) {
        this.reservationQueue.push(reservation);
        console.log("adding reservation to queue");

        if (!this.isProcessingQueue) {
            await this.processReservationQueue();
        } else {
            setTimeout(async () => {
                console.log("End waiting after 3 seconds!");
                await this.processReservationQueue();
            }, 3000);
        }
    }

``` this is my solution so far but it looks shiit

i think the problem is that, the databaseService is created in the command. so i think i must provide the connections first then i can collect everything in the queue. how do i determine the Guild before a command happens?

frosty copper

Why implement it in js when transactions on databases exist for this exact use case?

pulsar mica

well then i dont understand how it works, my problem is DatabaseService gets created when a slahscommand happens

how would i do that with mongoose?

so that means 2 ppl hitting the command at the same time. i create 2 transactions