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
Tag: mongodb
MongoDB error on Transaction w/ ReadPreference Secondary on a test replica set
tl;dr How can I enable read preference SECONDARY on a single-operation read transaction, on a testing replica set? I have created a MongoDB replica set from MongoDB deploy replica set for testing. Then tried to make a simple, single-document transaction from MongoDB Transactions where I only change a few things such as read preference to secondary. I get the following
Django(djongo) can’t connect to MondoDB Atlas after Heroku deployment
I managed to get it working locally (different cluster, separate settings.py), but not after when deployed to Heroku. Heroku – automatically adds DATABASE_URL config var with a postgresql, and I cannot remove/edit it. MongoDB Atlas – I’ve set the MongoDB Atlas cluster to allow IPs from everywhere. And the password has no funny characters. django production settings.py I ran migrate
Updating a pre-exiting fields datatype(string=> date) in a mongoDb collection
I am trying to update a field that was initially captured as a string instead of a date type. Currently, the query that insert into the collection has been modified , so that future insert to that field is date. data type However, I am trying to update the previously inserted data, before query modification that still has the string
Using MongoDB on Discord.py for scheduled tasks
Purpose I have some commands like temp-mute, temp-ban, and other commands that need to be done after commands execution, and I do need to schedule things like giveaways and trigger a function as soon as the subscription ends, from a command. What do I want? I want to store all my timings and things in MongoDB and then make it
How to convert a whole column from string type to date type in mongodb with pymongo
My data consist of 1million rows. A sample look like this: The thing is that date2 and date4 are in the form that i want but they are string and i want to convert them to date. The code i have used look like this: Do i need to convert them before inserting or after? Does anyone know how i
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
pymongo update all documents in collection for field with it’s substring value
Desired output in other words substring [:3] How can I achieve this with pymongo Answer You can use updatemany with an aggregation : https://docs.mongodb.com/manual/tutorial/update-documents-with-aggregation-pipeline/
Python SSH tunnel into EC2 and connect to DocumentDB
I have been attempting to SSH tunnel into an EC2 instance and connect to DocumentDB that is located in the same VPC. I’ve tried all of the solutions I could dig up online with no luck. I am using the ssh_pymongo module, which wraps SSHTunnelForwarder. I am able to SSH directly into the EC2 instance and connect to the DocumentDB