T
T
TheMurkovich2020-10-13 21:43:42
Python
TheMurkovich, 2020-10-13 21:43:42

How to check if a specific document exists in PyMongo?

Is there any way to check a specific document in PyMongo? Tried like this:

@client.command(name='bio')
async def bio(ctx):
    if collection.find_one(ctx.author.id)["bio"] is None:
        emb = discord.Embed(title=f"Биография **{ctx.author.name}**", description="```Нету биографии```",
                            colour=discord.Colour.blue())
        await ctx.send(embed=emb)
    else:
        emb = discord.Embed(title=f"Биография **{ctx.author.name}**", description=collection.find_one(ctx.author.id)["bio"],
                            colour=discord.Colour.blue())
        await ctx.send(embed=emb)

But got this error:
if collection.find_one(ctx.author.id)["bio"] is None:
TypeError: 'NoneType' object is not subscriptable

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-10-13
@TheMurkovich

if collection.find_one(ctx.author.id) is None:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question