import pymongo
client=pymongo.MongoClient("mongodb+srv://Debaditya:<password>@pycluster.d6kvk.gcp.mongodb.net/<db>?retryWrites=true&w=majority")
db = client.test
db.command("createUser", "sample", roles=["read"])
请帮我上面给出的代码
以下是在集合中插入文档的示例代码。
from pymongo import MongoClient
client = MongoClient("mongodb+srv://Debaditya:<password>@pycluster.d6kvk.gcp.mongodb.net/<db>?retryWrites=true&w=majority")
db = client.test
db.students.insert_one({"name": "Test User", "rollNo": 37})
在上面的示例中,students是您插入上面一行的集合名称。
如果要列出集合中的行。
list(db.students.find())
刚刚通过了pymongo在这里的文件