Error during insert_one in database

I made a discord bot in python , now I am trying save my data on database instead of local files. I am trying to use insert_one in database but it show error . Its very basic code but dont know why this problem apper while all you tube , tutorial said its ok. My code is:

async def data(ctx, member:discord.Member):
    mycol = mydb["data"]
    await ctx.send(f"checkpoint 1")
    await ctx.send(f"checkpoint 2")
    mydict = {  "_id": member_id, "name": "John", "gender": "M", "area": "US", "age": 33}
    await ctx.send(f"checkpoint 3")
    await ctx.send(f"checkpoint 4")

at checkpoint 3 it works ok and print also but nextline it create error . What may be the reason? Any help will be appriciated.

Hello @Shubh_Singh

It would be helpful for others to read and respond to your question if you could apply the proper code formatting to your post.

You can find in Formatting code and log snippets in posts a detailed description from @Stennie on formatting code.

• Add triple backticks (```) before and after a snippet of code. This syntax (aka code fencing in GItHub-flavoured Markdown) will automatically detect language formatting 1 and generally be an improvement over a straight copy & paste.

• Log lines can be formatted better by prefixing with > (aka quoting). This will wrap long lines and provide some visual distinction from code blocks. The editing toolbar has a shortcut for toggling line quoting on the currently selected text: . You can also use the (```) formatting for log snippets, but quoting generally works better.

• Add spacing to break up long blocks of text and improve readability


Without the error message you are getting, it is very hard to tell. Please post the exact error you are getting.

Thanks for you reply. It creates CommandInvokeError.
Also when I use command “find_one” it works nice when data available but when data not available in collection ( I mean different data is available not not matched with find_one) then it creates CommandInvokeError.

Please post screenshot of both situations.


Thank you sir for your concern, at present I resolved my problem.

Could you please share what was the root cause of your problem?

This would help others apply the same solution if the have a similar issues.

Yes… My ip address was connected but when i connect it as then it started working

at present when I use count() function to count document in any collection then it works fine but showing message to use count_documents function but when I use count_documents instead of couny() it raise error… perhaps I dont know exact syntax of count_documants

If you want us to help you with that you will have to share the code so that we see how you use it. It will also be very helpful to see the exact error that is raised.


This code still uses count() rather than count_document().

And please

I strongly recommend you take the MongoDB University course M220P for python.

ok… do you know syntax for count_document()
I used like

No, but I would start by looking at the documentation:

thanks… seems compatibility issue

Please elaborate so that others in the same situation knows how to resolve a similar problem.

While I await for your feedback on the compatibility issue you found, I went and look at the documentation I posted. It seems that you simply need to pass the empty query {} as the parameter to count_document() since this API does not have a default parameter. So now I

Sorry for late reply, I could not come online. I resolved issue by ignoring warning as:

import warnings
warnings.filterwarnings(“ignore”, category=DeprecationWarning)

I found this problem was very general and found solution when google.
At present my bot is running perfectly with MongoDb Atlas but when I connect it to to make it online 24/7 it connect but does not read data from MongoDb . I google but everywhere same process is explained which i did. links cant be wrong as it connect and work when i run it without I used free version of MongoDb , since my data are in kbs and I have allowed upto 512MB hence it should work. Any idea how to resolve this issue?