mongodb

How can I retrieve relative document in MongoDB?

How can I retrieve relative document in MongoDB? Question: I’m using Flask with Jinja2 template engine and MongoDB via pymongo. This are my documents from two collections (phone and factory): phone = db.get_collection("phone") { "_id": ObjectId("63d8d39206c9f93e68d27206"), "brand": "Apple", "model": "iPhone XR", "year": NumberInt("2016"), "image": "https://apple-mania.com.ua/media/catalog/product/cache/e026f651b05122a6916299262b60c47d/a/p/apple-iphone-xr-yellow_1.png", "CPU": { "manufacturer": "A12 Bionic", "cores": NumberInt("10") }, "misc": [ …

Total answers: 1

Accessing PyMongo UpdateOne operation properties

Accessing PyMongo UpdateOne operation properties Question: If I am receiving a list of prepared PyMongo UpdateOne operations (e.g. below)… print(type(to_load[0])) > <class ‘pymongo.operations.UpdateOne’> print(to_load[0]) > UpdateOne({‘id’: XXX}, {‘$set’: {‘name’: ‘YYY’}}, True, None, None, None) …is it possible to then extract information from these? For instance, if I want to get a list of all of …

Total answers: 1

discord.py how to remove documents in mongodb python

discord.py how to remove documents in mongodb python Question: I’m trying to remove one and also able to remove all documents in a collection on mongodb and I’m not sure what to do. @client.hybrid_command(name = "clearwarn", with_app_command=True, description="Delete a warn or all warns of a member", aliases=["clearwarns"]) @commands.guild_only() @commands.is_owner() @commands.has_permissions(moderate_members=True) async def clearwarn(ctx, member: discord.Member …

Total answers: 1

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 do you use pymongo to connect to mongodb atlas

How do you use pymongo to connect to mongodb atlas Question: I’m trying to connect to MongoDB Atlas but am having some difficulty, below is my code so far (I’ve removed my actual password from the MongoDB string hence why it just says password): import pymongo client = pymongo.MongoClient("mongodb+srv://ben:[email protected]/international_football?retryWrites=true&w=majority") print(client.list_database_names()) db = client.international_football print(db.list_collection_names()) I’ve …

Total answers: 2

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

Define field in Django which can be of any type

Define field in Django which can be of any type Question: Pymodm is being used to define my model for the MongoDB collection in Django. I want to declare a field that can store values of any type (List, String, or Integer).    from pymodm import MongoModel, fields class DefinitionEntity(MongoModel):     version = fields.IntegerField(required=True) …

Total answers: 1

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