PyMongo save List of dict in subfield with own ObjectId for every dict entry

I’m creating a list of Objects in my script, and want so save/update them in a subfield of an mongo db document. My Objects looks like this: class IndividualRating: def __init__(self, place=0, player="", team="", games="", legs=""): self.place = place self.player = player self.team = team self.games = games self.legs = legs in my process i’m… Read More PyMongo save List of dict in subfield with own ObjectId for every dict entry

Pymongo "and" operator not filtering query results

I have this monogdb schema: groups = { "bsonType": "object", "required": [ "created_at", "group_name", "owner", "members", "currency", "country", "group_username" ], "properties": { "created_at": { "bsonType": "date", "description": "The date and time when the group was created" }, "group_name": { "bsonType": "string", "description": "Name of group" }, "group_username": { "bsonType": "string", "description": "groups username" }, "country":… Read More Pymongo "and" operator not filtering query results

pymongo "Projection" to exclude all fields and only get selected fields?

Using mongodb projection we can define which filed to include and which one to exclude. like this : data = db.Users.find_one({‘username’: user },{"_id":0,"password":0,"email":1}) This Query will exclude the _id and password fields and only include email , But is there a way to exclude all the fields present in a document and only fetch email… Read More pymongo "Projection" to exclude all fields and only get selected fields?

Get data based on unique field mongodb during pagination

Sorry if the title is wrong but here is what i am trying to do, let’s say i have the objects : {"_id": "anyID0", "contentID": "content1", "value": "any value", "at": 10} {"_id": "anyID1", "contentID": "content1", "value": "any value", "at": 9} {"_id": "anyID2", "contentID": "content2", "value": "any value", "at": 8} {"_id": "anyID3", "contentID": "content3", "value": "any… Read More Get data based on unique field mongodb during pagination

How can I get a subfield of dictionary in mongodb?

I’ve the data structured as follows: { "_id" : ObjectId("61e810b946788906359966"), "titles" : { "full_name" : "full name", "name" : "name" }, "duration" : 161, "work_ids" : { "plasma_id" : "METRO_3423659", "product_code" : "34324000", } } I would like query result as: {‘full_name’: ‘full name’, ‘plasma_id’: ‘METRO_3423659’} The query that i do is: .find({query},{"_id": 0, "work_ids.plasma_id":… Read More How can I get a subfield of dictionary in mongodb?

How to find all documents in a collection Mongodb by two values of the same key?

Tried to find the answer on the net, but somehow did not work. I have a collection from which I get a dataframe. I need to filter, that is, get all documents in which the key value will match a certain list of values. Example collection: _id: ‘1’ key_1: ‘a’ key_2 : ‘b’ _id: ‘2’… Read More How to find all documents in a collection Mongodb by two values of the same key?

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