6,881 questions
0
votes
0
answers
51
views
pymongo is not inserting document with base64 string
I have data which pymongo fails to upload, and, I cannot understand why.
Data available here
main2.py:
from pymongo import MongoClient
import json
client = MongoClient(host='localhost')
db = client....
0
votes
0
answers
70
views
How can I programmatically determine if a PyMongo command is a read or write for permission logic (without a hardcoded command list)?
I'm building an authorization/access control system in a Python application that uses PyMongo to access MongoDB. I need to dynamically decide—at runtime and for arbitrary query shapes—whether a given ...
1
vote
1
answer
89
views
PyMongo MongoClient - is there a way to see number of open connections?
The docs say that each mongo client maintains a connection pool, the max size of which I can specify. Is there anyway to check the number of open connections made by a specific mongo client at a given ...
1
vote
1
answer
201
views
Pymongo and Beanie Incompatibility issues
I'm trying to migrate from motor to pymongo's AsyncMongoClient.
After doing some upgrading/installing on pymongo I am having the below error when running this import from beanie import Document
...
0
votes
0
answers
38
views
How to set timestamp on document update only when it's modified with MongoDB (pymongo)?
Let's say I have a command:
my_collection.update_one({...}, {
"$set": { "title": "Title 1" }
})
How to make it adding update_at field with current date when update ...
1
vote
3
answers
92
views
MongoDB count_documents() returns 19 but find() returns empty list - Replica Set Consistency Issue
I'm experiencing a consistency issue with MongoDB in production. I have a 3-node replica set deployed on OVH, and sometimes count_documents() and find() return different results for the exact same ...
0
votes
0
answers
70
views
Static typing for database schema models that handle foreign keys/dbrefs as `external_document: ExternalDocumentModel | DbRef`
We're using Python (3.12) with Pydantic models to represent schemas for our MongoDB collections, which we then instantiate with SomeModel.model_validate(<results of pymongo query>). We define ...
0
votes
1
answer
44
views
mongo add new properties instead of overwriting existing ones if using dot notation and arrays
i have a mongodb with documents containing a list of "pages", as sub-documents,
like
{
pages: [
{ a:1, b: "foo"},
{ a:2, b: "bar"},
]
}
now i want to update the ...
0
votes
1
answer
80
views
mongod db.killAllSessions() reports that it works, but doesn't kill the sessions
I'm very new to MongoDB and I'm trying to get the killAllSessions or one of its variants to work, in mongosh and/or using pymongo. I have a simple, standalone instance of mongod running in a Docker ...
0
votes
1
answer
86
views
MongoDB: rename a field with dot in it
I have a MongoDB collection that contains several fields with dots, like:
{
"symbol.name": "Some name"
"symbol.state": "Some state"
// etc.
}
Now, ...
0
votes
1
answer
43
views
Requesting clarity on PyMongo's maxIdleTimeMS parameter
per the official PyMongo's documentions for maxIdleTimeMS
maxIdleTimeMS (optional): The maximum number of milliseconds that a connection can remain
idle in the pool before being removed and ...
1
vote
1
answer
48
views
PyMongo - Group by year based on subdocument date
I have a MongoDB document like:
[
{
_id: ObjectId('67cfd69ba3e561d35ee57f51'),
created_at: ISODate('2025-03-11T06:22:19.044Z'),
conversation: [
{
id: '...
0
votes
1
answer
56
views
Update an array value in document with Pymongo
I am creating a tracker that tracks the usage of invites on discord and who used which invite when a member joins. I am storing the data in mongodb. I am having trouble update the uses value which I ...
1
vote
0
answers
84
views
Get MongoDB telemetry using Open Telemetry auto instrumentation for flask?
My company runs a Flask API connected to MongoDB on atlas. Currently, we have minimal logging and metrics and rely solely on Altas to monitor DB usage. This month we realized the DB is being queried ...
0
votes
0
answers
30
views
Jupyter_dash not loading a dash
I'm doing a project for school that uses an .ipynb file to create a dashboard and connect to a MongoDB collection to output a table and map. The code is here:
# Setup the Jupyter version of Dash
from ...