Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update operations don't seem to work together? #100

Open
IvesAwadi opened this issue Nov 22, 2024 · 1 comment
Open

Update operations don't seem to work together? #100

IvesAwadi opened this issue Nov 22, 2024 · 1 comment

Comments

@IvesAwadi
Copy link

Hello, I'm writing this because there's this bizarre issue within the library were using the $push and $set operations don't seem to work together? Is this something you could look into?

from montydb import MontyClient

# Create an in-memory database
client = MontyClient(":memory:")
db = client["test_database"]
collection = db["test_collection"]

# Insert sample data
collection.insert_one({
    "_id": "d85c43a583b90f50bc5cff50c066ff02",
    "CharacterRecords": [
        {"ID": "Custom_Character", "level": 50, "pendingTalentRerolls": [], "talentSlots": []},
    ]
})


try:
    collection.update_one(
        {"_id": "d85c43a583b90f50bc5cff50c066ff02"},
        {
            "$set": {
                "CharacterRecords.$[char].level": 10,
            },
            "$push": {
                "CharacterRecords.$[char].talentSlots": {
                    "$position": 0,
                    "$each": [
                        {'talentId': '??????'*2, 'rarity': 'Legendary', 'purchased': True}
                    ]
                }
            },
        },
        array_filters=[{"char.ID": "Custom_Character"}]
    )
except Exception as e:
    print(e)

Using pymongo, this query works as expected but it doesn't seem to work with montydb.
I was trying to debug to see if I could fix it, but everything is so confusing so I could not do anything.
Thank you.

@davidlatwe
Copy link
Owner

Hi, thansk for reaching out. 😃

I was trying to debug to see if I could fix it, but everything is so confusing so I could not do anything.

It is really cool that you have tried fixing it! But MongoDB update operators are not easy to fix/improve with current codebase, it is confusing as you already find. 😭

To be honest, I don't have much resource for maintaining montydb recently. I will try, but please do not expect any good news soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants