pymongo

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

pymongo "Projection" to exclude all fields and only get selected fields? Question: 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 …

Total answers: 1

Mongodb find nested dict element

Mongodb find nested dict element Question: { "_id" : ObjectId("63920f965d15e98e3d7c450c"), "first_name" : "mymy", "last_activity" : 1669278303.4341061, "username" : null, "dates" : { "29.11.2022" : { }, "30.11.2022" : { } }, "user_id" : "1085116517" } How can I find all documents with 29.11.2022 contained in date? I tried many things but in all of them …

Total answers: 1

How to add my own parameters into pymongo find function

How to add my own parameters into pymongo find function Question: 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 …

Total answers: 1

How do I push to a nested array in a PyMongo database?

How do I push to a nested array in a PyMongo database? Question: I have a MongoDB database with the following structure (simplified for the question’s sake): User: "id": int "aquarium": Aquarium[] Aquarium: "name": str "fish": Fish[] I have access to: The database, which contains a list of objects of type User, which in turn …

Total answers: 2

Cannot deserialize properly a response using pymongo

Cannot deserialize properly a response using pymongo Question: I was using an API that were written in NodeJS, but for some reasons I had to re-write the code in python. The thing is that the database is in MongoDB, and that the response to all the queries (with large results) includes a de-serialized version with$id …

Total answers: 1

Why is find_one() timing out when find() works just fine using MongoDB?

Why is find_one() timing out when find() works just fine using MongoDB? Question: The code below connects to MongoDB, then attempts to find the specified record, which exists. The collections are very small. client = pymongo.MongoClient("PRIVATE_MONGO_ACCESS_HERE?retryWrites=true&w=majority") db = client.my_db score_holder = db[‘app_data’].find_one({‘score_holder’: True}) Result: pymongo.errors.ServerSelectionTimeoutError I’m pretty sure the above code was working fine a …

Total answers: 1

Is there a function to only extract/return the value of a field with Pymongo?

Is there a function to only extract/return the value of a field with Pymongo? Question: I’m using MongoDB and want to work with it in Python which is needed for my project. I wanted to extract only the value of a specific field with Pymongo. In my case, I tried returning the name of a …

Total answers: 1

pymongo sort dictionaries inside of an array by date

pymongo sort dictionaries inside of an array by date Question: I want some of your knowledge in here. What I’m trying to do, is to sort the dates (datetime) of the dictionaries (from the oldest to newest) which is inside of an array from my MongoDB database. {"_id": { "$oid": "63595cb35e81b89cb442087c", "Carrots": [ { "task": …

Total answers: 1

(Pymongo) connect/adding relationship with two column from different collections in MongoDB

(Pymongo) connect/adding relationship with two column from different collections in MongoDB Question: I’m practicing use python to commit rollback MongoDB (Pymongo) For example, I have two collections, one collection store all amount of money of each user and log collection is saving data of with roll or input money in bank total_money_collection {"user": "Joy" , …

Total answers: 1

fastapi mongodb how to add pagination and limit number of items per page?

fastapi mongodb how to add pagination and limit number of items per page? Question: I am using pymongo. Category.city_collection.find() getting all collection of result. But I want to show only 5 result per page. I tried this Category.city_collection.find().limit(5) which showing 5 result on first page but how to go others page like second page, third …

Total answers: 1