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… Read More How to sort by year using a date string in PyMongo Aggregate

Smart way to update all documents in mongodb using python function

I execute some_python_function on all elements of collection. This function returns different values for each document. I developed the following function, but it’s very slow. for doc in db.collection.find(query, projection): result = db.collection.update_one( {"_id": doc["_id"]}, {"$set": {"field": some_python_function(doc["field"])}} ) I am looking any smarter way to do it, rather than updating documents one-by-one. What would… Read More Smart way to update all documents in mongodb using python function