之後應該會出現這個畫面
點擊Add new project
next後,create the Project
創建資料庫
選免錢的
create
點擊Database Access
自己設定密碼
點擊Network Access,Add an IP address(右邊的按下去)
回到Database,點擊Browse Collection、Add My Own Data
回到Database,點擊Connect
點中間的
複製程式碼
#這是範例
mongodb+srv://admin:<password>@cluster0.ltujo.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
pip install mongo
import pymongo
from pymongo import MongoClient
cluster = MongoClient("剛剛複製的,password換成自己的就好")
db = cluster['discord_bot_database']
collection = db['data']
post = { "name" : "12345"}
collection.insert_one(post)
import pymongo
from pymongo import MongoClient
cluster = MongoClient("剛剛複製的")
db = cluster['discord_bot_database']
collection = db['data']
findone = collection.find_one({'name' : '12345'})
print(findone)
import pymongo
from pymongo import MongoClient
cluster = MongoClient("剛剛複製的")
db = cluster['discord_bot_database']
collection = db['data']
first_data = {'name':"12345"}
second_data = {"$set" : {"name":"50000"}}
collection.update_one(first_data, second_data)
print("Successful")
import pymongo
from pymongo import MongoClient
cluster = MongoClient("剛剛複製的")
db = cluster['discord_bot_database']
collection = db['data']
del_data = {"name":"50000"}
collection.delete_one(del_data)
print("Successful")