MongoDB database interface syntax 关注
I'm trying to program something that can import a ton of data from Excel and insert it into a MongoDB Atlas database.
I'm a relatively proficient programmer but completely new to Python and MongoDB so please excuse me for asking stupid questions.
I can get the data in form Excel but need a little guidance on the principles of how to write code that will put data into MongoDB. I use the professional version of PyCharm and have managed to setup a functioning database connection to my MongoDB and can make queries in the console but I can't get my head around how to access the DB from code in a .py file
Any guidance will be very much appreciated :-)
请先登录再写评论。
You can do it directly from the init.py's main function like this (taken from a tutorial here):
Contents of init.py:
Or you can write the code in a separate .py file, then just import it as a module to any file with an executable function and call it from that function. See my example below (taken from this tutorial):