Josh
Josh

Reputation: 164

TinyDB remove WHERE multiple values are true

In Python, I'm trying to remove an entry from TinyDB where 2 values match.

Example DB:

{
    "_default": {
        "1": {
            "GuildID": 123,
            "RoleName": "role"
        },
        "2": {
            "GuildID": 321,
            "RoleName": "role"
        }
     }

If I do

db.remove(where('RoleName' == role))

It will remove both entries, but I don't want that. I want to match on GuildID and RoleName

I thought this would work, but apparently not

db.remove(where('RoleName' == role) & ('GuildID' == 321))

The above query doesn't find any values at all in the DB, but I want it to delete entry 2

Upvotes: 0

Views: 1208

Answers (1)

Josh
Josh

Reputation: 164

Fixed, I used TinyDB's Query function

from tinydb import Query
QueryBuilder = Query()
db.remove((QueryBuilder.RoleName == role) & (QueryBuilder.GuildID == 321))

Upvotes: 0

Related Questions