Skip to content

Tag: mongodb

Get amount of objects saved in MongoDB using Pymongo

I’m trying to get amount of objects saved in MongoDB with but I’m getting an error I’m using Pymongo 2.0 Answer The find() function for pymongo returns a cursor object (not an array). Pymongo does include a count_documents function. Meaning the code should look like this: Edit: Updated to co…

Mongo db array of images change schema

I have an array of images in mongodb and I am trying to change the schema of the array. Right now the images are stored like bellow And the final output I want is like bellow. How can I do this in mongosh? Is it easier to do this as a Python Array and then import back to mongodb? Thank

“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…

$elemMatch to fetch specific values inside array

I have a collection named ‘attendance’ that has an array: I have been trying to query the values of the specific element in my array using $and and $elemMatch in: But it still prints the other section rather than one. I want to output to be: And I tried using the dot notation like: Still no luck. …

Conditional call of a FastAPI Model

I have a multilang FastAPI connected to MongoDB. My document in MongoDB is duplicated in the two languages available and structured this way (simplified example): I therefore implemented two models DatasetFR and DatasetEN, each one makeS references with specific external Models (Enum) for category and tags in…