Skip to content
Advertisement

Tag: mongodb

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: 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! Answer

pymongo converts . variables into a dict

I am inserting the data to mongoDB collection through pymongo. I have logged all the information and data which is being sent to update_one statement. Data which is logged just before update_one statement : But when it got inserted into “test” then it got appended like this : Using this to update the document: So here you’ll see parsed data

MongoDB update object rather than insert a new one

Using collection.insert_one(json_dict)inserts a new collection Can I do collection.insert_one() on an already existing object so it then updates. My object will look something like: Then under “Age” I want to add “Location”: “New York’, how’d I do that using PyMongo Answer I you want to add new field to existing document, you need to update it. There is a function

Advertisement