Md Shahriyar Alam
2 months 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.
First you have to create a project on MongoDB Atlas and get the connection url from there
MongoDB Atlas: https://www.mongodb.com/atlas/database Free
Railway:
https://railway.app/ Free | Paid
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.
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#1 Custom commands discord bot available on the internet
20-22 Wenlock RoadEnglandN1 7GU
© WEiRDSOFT LTD. All rights reserved.