0

I got the following problem. I'm trying to pull the specific field, in the "warnings" array, which has the given UID. I can't seem to figure out why it's not working.

The output (Everything prints out successfully): https://i.imgur.com/ZslJ0rV.png\ My MongoDB structure: https://i.sstatic.net/XsCqS.png

client = pymongo.MongoClient("")
database = client["LateNight"]
ModlogsCollection = database["modlogs"]



theUID = "63TF-lYv0-72m7-9f4I"
theGuild = 1063516188988153896



all_mod_docs = ModlogsCollection.find({"_id": str(theGuild)})
all_uids = []



for doc in all_mod_docs:
    doc_keys = [key for key in doc.keys() if key != "_id"]
    for key in doc_keys:
        sub_doc = doc[key]

        if warnings := sub_doc.get("warnings"):
            for warning in warnings:
                if warning["UID"] == theUID:
                    print(warning)
                    print("Warning")
                    result = ModlogsCollection.update_one(
                        {"_id": str(theGuild)},
                        {"$pull": {
                            "warnings": {"UID": theUID}
                        }}
                    )
                    print(result)
                    print(result.modified_count)
1

1 Answer 1

0

as you yourself said you try to "extract the specific field, in the warnings table that has the UID given". Before recovering the UID value you must specify the index 0. Afterwards you get a dictionary that will have the keys: moderator, reason, time and UID

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.