D
D
Dream2021-05-29 15:46:12
Python
Dream, 2021-05-29 15:46:12

How to check if a list is empty in MongoDB?

(I use: MongoDB, Python and Discord.py)
How to check if a list is empty? I tried to do it, but for some reason the bot sends an empty message when the list is empty.

@bot.command()
async def test(ctx):
    products = collection.find_one({"_id": ctx.author.id})["products"]
    if products == None:
        msg = "Пусто"
    else:
        msg = products
    await ctx.send("Продукты:", msg)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Romanov, 2021-05-29
@dreameddd

If you need to check the list for emptiness, then instead of:

if products == None:
        msg = "Пусто"

if not products:
        msg = "Пусто"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question