Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
MongoDB row as variable Javascript Discord

I building a game thingy where you can trade and stuff. I'm currently making the admin command for it, so that you can give members amounts of materials. Here is the code:

      try {
        const targetData = await profileModel.findOne({ userID: target.id });
        if (!targetData) {
          return message.channel.send(config.basemessages.messagesaccountmissing);
        }
        await profileModel.findOneAndUpdate(
          {
            userID: target.id,
          },
          {
            $inc: {
              bank: amount,
            },
          }
        );

        message.channel.send(`The targeted member has been given \`${amount}\` amount of \`${material}\`.`)
      } catch (err) {
        console.log(err);
        message.channel.send(`Error executing command. EC: \`${config.errorcodes.err2}\`.`) // Error Systeem
      }

Since I have 200+ different items, it would be inefficient if I copy this block 200+ times just to give someone a item. The problem is that bank should be the exact name of a row in a MongoDB document. I just discovered that you can't make that a variable (or so I think). I want to replace that with for example material, where material is args[1] (the perimeter). Example usage:

$give @member iron 40
  • Member = the target Discord member (args[0])
  • Iron = the material that I want to increase (args[1])
  • 40 = amount to increase (args[2])

I hope it's clear what I mean. Is there a work around this? (Only the bank perimeter doesn't work, the amount does work with a variable).

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!