我有这种结构的文档。我需要更改数字 3,待处理 --> 完成 有没有可能的方法可以做到这一点, 谢谢你的帮助❤️
db.Queue.find({"dr-name":"1guna"},{ "queue.0":1 }) 不返回任何东西
{ _id: ObjectId('6623b76f360aa86eb3560898'), queue: [ [], [], [], [], [] ] }
[{
"_id": {
"$oid": "6623b76f360aa86eb3560898"
},
"dr-name": "1guna",
"live-number": "0",
"est-number": "17",
"queue": [
[
"1",
"Banduka_Chamaras",
"07:16:43",
"pending",
"1711111919"
],
[
"2",
"chicken_Chamaras",
"07:17:57",
"pending",
"0711111116"
],
[
"3",
"butter_Chamaras",
"07:29:11",
"pending",
"0711111516"
],
[
"4",
"kaslisda_sds",
"06:33:47",
"pending",
"5433454534"
],
[
"5",
"kaslisda_sds",
"07:13:42",
"pending",
"5433454539"
]
]
}]
使用pymongo
pip install pymongo
更新元素的示例代码:
from pymongo import MongoClient
# Connect to the MongoDB database server (change 'localhost' and '27017' as necessary)
client = MongoClient('mongodb://localhost:27017/')
# Connect to the specific database and collection
db = client['your_database_name'] # Replace 'your_database_name' with the name of your database
collection = db['Queue']
# Query to find the document
query = {"dr-name": "1guna", "queue.2.0": "3"}
# Update statement to change the status
update = {"$set": {"queue.2.3": "Done"}}
# Perform the update
result = collection.update_one(query, update)
# Output the result of the update
print("Documents updated:", result.modified_count)
# Close the connection
client.close()