Skip to content

Tag: pymongo

How to add my own parameters into pymongo find function

Im building a python application that allows you to query data from mongoDB based on the start time and end time that the user puts in. I have been able to connect to mongoDB and put data there. I just cant seem to get the query right. I will show only the function in question because I know that connecting

How can I limit output of MongoDB query in Python?

I have this example MongoDB entry in a users DB: And I’m using Pymongo to query the file named “test”: users.find_one({‘files.filename’:”test”}) How can I limit the output from Pymongo, so it only gives me the dict where “test” is contained? In other words…

How to sort by year using a date string in PyMongo Aggregate

Me and another programmer have run around in circles on this and cannot seem to find an answer online. We have a MongoDB collection into which we have inserted documents which have been pulled from an API. Each document has a field called attributes.created which is a string. The format of the string is like …

Aggregation $match within a $sum

I was wondering if it was possible to somehow use the $match operator within the $sum function for aggregation. I want to be able to use the value of the $sum operator within the project fields somehow, I just don’t really understand what the right approach would be for this. Sample Input (may be too lo…

“Update” _id in mongodb document

PS: I only have to do this due to business requirements I’m able to achieve it using mongosh, but since there are multiple records to be updated, I’m trying to implement a simple python script to automate the task. Is it possible to do this with pymongodb? I’m not able to set the new Id in t…

How to wait pymongo find() results without looping all rows?

Not getting any result in pymongo by find() function in my collection: But if I loop that variable, then it loads: The only thing I did is adding a loop (see line ): So if I put that loop it will load all rows and I will see retrieved: 46 How can I wait it to return results without looping