pymongo

MangoDB using JavaScript Pattern with $in operator

MangoDB using JavaScript Pattern with $in operator Question: Trying to create a MongoDB query with the Pymongo driver that search a database for some dog breeds, but I need to do pattern matching due to data being of differing quality. I know I cannot use Regex in a $in style query so I am using …

Total answers: 2

pymongo | InvalidOperation while trying to return result

pymongo | InvalidOperation while trying to return result Question: I’ve been trying to make something using MongoDB with the help of pymongo python package but I’ve encountered a error that I can’t solve. So basically, I used the collection.find() function to assign the returned data to a variable and then tried to return a row …

Total answers: 1

How can I limit output of MongoDB query in Python?

How can I limit output of MongoDB query in Python? Question: I have this example MongoDB entry in a users DB: { _id: xxx, name: "name", files:[{ fileName: "test", size: 654 }, {fileName: "test2", size: 50 }] } And I’m using Pymongo to query the file named "test": users.find_one({‘files.filename’:"test"}) How can I limit the output …

Total answers: 1

How to filter mongodb documents based on objects in array?

MongoDB – How to filter documents based on objects in array Question: I have the following type of documents in my MongoDB database: [ { "_id": { "$oid": "63267309592e38db589c576d" }, "name": "ASOS DESIGN tapered smart shorts in white and navy stripe", "color predictions": [ { "Beige": { "$numberInt": "1" } }, { "Black": { "$numberInt": …

Total answers: 1

How can I get a subfield of dictionary in mongodb?

How can I get a subfield of dictionary in mongodb? Question: 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’, …

Total answers: 1

What can I do to output in MongoDB with $inc from always being decimal with 2 point accuracy? (rounding output)

What can I do to output in MongoDB with $inc from always being decimal with 2 point accuracy? (rounding output) Question: So I’m using MongoDB 6.0 (and motor driver in python) and for example I have a code like that: money = 4.92 from_snowflake = "19251" await db["bank"].update_one({"snowflake": str(from_snowflake)}, {"$inc": {"balance": -float(money)}}) and assuming the …

Total answers: 1

Pymongo Not inserting full document on update_one

Pymongo Not inserting full document on update_one Question: I have a lot of documents to update and I want to write a timestamp initially and then an update timestamp when there are duplicates. So I found this answer and am attempting it for MongoDB 6.0 https://stackoverflow.com/a/17533368/3300927 I also store in my model the variable to …

Total answers: 1

Unable to convert decimal to Decimal128 in python

Unable to convert decimal to Decimal128 in python Question: My Django project (python==3.10.3, Django==4.0.4) is accessing an MSSQL server via pymssql (pymssql==2.2.5), scraping what I need, and getting a list of dicts. I then save to MongoDB (pymongo==4.2.0) but there are decimal values that need to be Decimal128. I found Pymongo: Cannot encode object of …

Total answers: 1

How to sort by year using a date string in PyMongo Aggregate

How to sort by year using a date string in PyMongo Aggregate Question: Me and another programmer have run around in circles on this and cannot seem to find an answer online. We have a MongoDB collection into which we have inserted documents which have been pulled from an API. Each document has a field …

Total answers: 1

PyMongo – How to query the number of properties in the object

PyMongo – How to query the number of properties in the object Question: I need to retrieve numerical data from hundreds of documents looking like this one: { "_id": "123", "Notes": { "1222": "Something is here" }, "BehavioralData": { "Folder1": { "Sex": "Male", "Age": "22", "Date": "", "ResearchGroup": "", "Institution": "University of Manitoba" }, "MoCA": …

Total answers: 1