Skip to content
Advertisement

Tag: mongodb

How can I limit output of MongoDB query in Python?

I have this example MongoDB entry in a users DB: And I’m using Pymongo to query the file named “test”: users.find_one({‘files.filename’:”test”}) How can I limit the output from Pymongo, so it only gives me the dict where “test” is contained? In other words, I want it to output this: Answer Here’s one way you could do it. Try it on

Inserting a request.form.items() list into a mongodb collection / Adding list of lists into mongoDB

I have the following code: I use for x in request.form.items() to loop through a dynamically generated form. Users create custom fields that can be added. I then add the results to a list of which an example of a print out is: [(‘name’, ‘David’), (‘phone’, ’90’), (’email’, ‘inf’), (‘company’, ‘Ran’), (‘Kids Names’, ‘Kids Names’), (‘Kids Birthday’, ‘2022-08-03’), (“Wife’s Email”,

Aggregation $match within a $sum

I was wondering if it was possible to somehow use the $match operator within the $sum function for aggregation. I want to be able to use the value of the $sum operator within the project fields somehow, I just don’t really understand what the right approach would be for this. Sample Input (may be too long): https://www.toptal.com/developers/hastebin/ixamekaxoq.json Sample Output: (

User-created Record Fields

I am creating a web-app w/ Flask + Flask-WTF that has CRM-like features as a project. My current database (MongoDB) structure is I have: Users who can login, People who are assigned to users, and Records who are assigned to people. People have various fields to be filled out (Name, Phone Number, Email, etc). I want Users to be able

Does mongo db ListField maintain ordering?

If I add items to a ListField on a mongo db document in a specific order and then write it to the database, is it guaranteed that all subsequent reads will see the list in the same order? e.g. write read this is using python mongoengine ORM v0.4.2 Answer Yes they do, the driver is faithful to the underlying data

How to construct pymongo query string from dictionary

My MongoDB documents looks like {‘k1’: ‘v1’, ‘k2’: ‘v2’, ‘k3’: ‘v3’ . . .} Would like to construct a pymongo query string where Keys and Values in maDict are Match, gtDict are greater than and ltDict are less than and display only the fields specified in diDict: I could think of converting each dictionary to construct the query string. Is

Convert SQL Query to MongoDB syntax

I have a big problem with converting SQL queries to Mongo DB for Python. I have a question if you know better methods for transferring SQL queries to Mongo DB queries? I have two queries but I still have big problems with the syntax conversion to Mongo DB. Maybe there is someone here who can help me? Table I have

Advertisement