Skip to content
Advertisement

How to dynamically code collection name inside a function?

I am trying to code a Python function to insert my CSV file to MongoDB database using MongoClient() but I don’t know how to dynamically code the collection name. Here is my code:

JavaScript

If I write my code like above, the collection name will be “file_name” instead of the parameter file_name. Anyone knows how to fix this? Thank you!

Advertisement

Answer

You can reference the collection using this format:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement