Use MongoDB with slash commands

Md Shahriyar Alam

4 days ago

To use MongoDB database, which is a cloud database with Slash Commands to store, find, update and delete data we can use the MongoDB function in this bot.

Database creation

First you have to create a project on MongoDB Atlas and get the connection url from there MongoDB Atlas: https://www.mongodb.comhttps://www.mongodb.com/atlas/database Free Railway: https://railway.apphttps://railway.app/ Free | Paid

Code

py# initialization of database
db = MongoDB(
    "connection_url",
    "database_name",
    "collection_name"
)

# insert data
await db.insert_one(
    { "name": "Anything", "age": 21 } # you can insert any data
)

# insert multiple
await db.insert_many([
    { "name": "Anything 1", "age": 21 },
    { "name": "Anything 2", "age": 22 }.
    { "name": "Anything 3", "age": 23 },
])

# find data
data = await db.find({"age": 21}) # it returns a list of data
# [ { "name": "Anything 1", "age": 21 } ]
data = await db.find_one({"age": 21}) # single data in form of an object
# { "name": "Anything 1", "age": 21 }

# delete data
await db.delete_one({"age": 21}) # deletes one row
await db.delete_many({"age": 21}) # deletes multiple row 

# update data
await db.update_one(
    {"age": 21}, 
    { 
        "$set": { "age": 99 } # remember to use $set
    }
)

await db.update_many(
    {"age": 21}, 
    { 
        "$set": { "age": 99 } # remember to use $set
    }
)

If you have any question make sure to join support server and ask questions on the help channel by creating a post.

Need help?

If you still need any kind of help, have a suggestion for us or having a question in mind? Feel free to reach us out.

Join support server
logoCustom Commands

#1 Custom commands discord bot available on the internet

We Accept

stripe

Contact

20-22 Wenlock RoadEnglandN1 7GU

© WEiRDSOFT LTD. All rights reserved.