Questions tagged [pymongo]
PyMongo is the official Python driver for MongoDB created and maintained by MongoDB, Inc. Please mention the version of PyMongo you're using.
6,825
questions
0
votes
0
answers
6
views
How to rollback partial inserts in MongoDB replica sets in presence of writeconcern
Consider a 4 member MongoDB replica set. Consider also that we use writeconcern(w:4) during insertions to achieve consistency. Then, if one of the replica set members is off, the insertion will "...
0
votes
0
answers
9
views
How to add additional method to pymongo Collection, Cursor objects?
Hello I have a small problem and I am not sure how to solve it:
Well, I am working with the pymongo library and I want to do something like this so that the Collection, Cursor or CommandCursor object ...
0
votes
0
answers
27
views
How to specify mongodb version from pymongo?
I have a mongodb server version 4.4 and I am upgrading the pymongo version to 4.5.0. Pymongo says it is compatible with vast versions, including 4.4.
How I specify the mongodb version for pymongo?
The ...
0
votes
0
answers
18
views
Why find function not returning all the fields's data properly of the document from MongoDB?
We have written some code in Python using pymongo to do fetch and update queries from MongoDB database. The flow of code is like:
Fetching from the database
Do some consolidation
Update the ...
-2
votes
0
answers
19
views
500 Internal Server Error Postman, Flask y MongoDBCompass
Hi I am using mongo compass and when I make a POST or even GET request (in Postman) I get that error "500 INTERNAL SERVER ERROR". Does anyone know why? It is the first time I am using these ...
0
votes
0
answers
26
views
Slow down in mongodb when performing bulk insert of more than 5 million documents in batch of 1000
I'm trying to read and process documents from a collection containing 14 million documents with an average size of 0.7Kb. After adding a new field, I'm performing bulk insert into a different empty ...
0
votes
0
answers
12
views
why pymongo 3.7 SocketChecker set select.POLLIN in _EVENT_MASK
In pymongo 3.7 SocketChecker, why the _EVENT_MASK had a select.POLLIN | select.POLLPRI?
From My Understanding, pool use the SocketChecker.socket_closed to check the socket obj status, reconnect this ...
2
votes
1
answer
38
views
Mongodb transactions fail to roll back changes when exception triggered
Ive set up a replicaset on a server with a primary, secondary and arbiter instance of mongodb. Firewall exceptions passed, all three instances are able to communicate with each other. Im testing out ...
1
vote
1
answer
33
views
PyMongo: [SSL: CERTIFICATE_VERIFY_FAILED]
I am new to MongoDB and am trying to connect to it using Python. I got most this code from the tutorial (i filled in the placeholders):
from pymongo.mongo_client import MongoClient
# Replace the ...
3
votes
3
answers
119
views
+100
Filter on MongoDB Vector Search doesn't work as expected
I'm building an aggregation pipeline in mongodb and I'm encountering some unexpected behaviour.
The pipeline is as follow:
[{
"$search":{
"index":"vector_index",
...
0
votes
1
answer
40
views
Mongo DB .find_one(query) doesn't find results
I am trying to check if a user exists in my database based on the contact information (name, surname, email) that I have retrieved from data. I know that this information exists in my database but for ...
1
vote
1
answer
41
views
How to insert small int values to NumberLong in document DB / mongo DB by using python/pymongo
When we are trying to insert small integer values let's say 45 to documentDB.
It's been saved as just an integer/Number value in documentDB.
But I want that to be saved as NumberLong irrespective of ...
0
votes
0
answers
25
views
No replica set members match selector "Primary()" using Python(pymongo)
I am having a ServerSelectionTimeoutError No replica set members match selector "Primary()" when executing a connection to a mongodb database using pymongo. previously this connection string ...
1
vote
0
answers
15
views
Create user with Pymongo
I am trying to create database user through Pymongo 4. Since add_user API is deprecated I have to issue a command on the admin database like this
db.command("createUser", username, pwd=...
3
votes
0
answers
29
views
Aggregate indexes of document with same name
I have a vectorstore in mongodb. The schema is as given below
Inside my vectorstore_db database, I have a value_embeddings collection and within that are documents which have indexes of various ...
1
vote
1
answer
30
views
Insert if it doesn't exist, update based in ADDITIONAL condition [mongoDB]
I'm creating a sync system in which I have the following type of data:
records = [
{'_id': 0, 'name': 'John', 'sync_date': '2022-01-01 00:00:00'},
{'_id': 1, 'name': 'Paul', 'sync_date': '...
0
votes
0
answers
31
views
Python List to save in MongoDB
I have an excel sheet of data. I made each rows as an dictionary and then appended them in a Python list. I am trying to save my Recipes list into the cluster but it shows error.
import sys
import ...
0
votes
1
answer
67
views
Unable to connect to Azure Cosmos DB for MongoDB vCore using pymongo
I'm trying to setup the connection for my MongoDb vCore cluster using pymongo, here is the code I have used
mongo_conn = "mongodb+srv://"+COSMOS_MONGO_USER+":"+COSMOS_MONGO_PWD+&...
0
votes
0
answers
36
views
store a matrix in Mongodb and query a single value using two keywords
I want to store the following matrix (shown in attachment) in MongoDB. I am using Python. I want to store the data as a matrix (or a more convenient alternative) and be able to query a single value ...
0
votes
0
answers
196
views
TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:1129),SSL handshake failed:
Im trying to connect from azure into mongo atlas in python throw pymongo.
I tried to connect with uri or with mongo atlas certificate.
from pymongo import MongoClient
from pymongo.server_api import ...
0
votes
1
answer
122
views
MongoDB Atlas ServerSelectionTimeoutError: SSL handshake failed
I'm having a hard time fetching some data from my mongodb database using pymongo driver. I keep getting the following error:
pymongo.errors.ServerSelectionTimeoutError: SSL handshake failed: ac-...
0
votes
0
answers
25
views
Get executionStats.executionTimeMillis from aggregate
I am using python3.10 with pymongo I want to get the execution time, I don't want to use time.time or some similar library since I only want the query time
pipeline_ref3 = [
{"$match": {...
0
votes
0
answers
28
views
Add new data to mongo DB, using certain conditions
I am trying to create a chatbot which could take tag, patterns and responses from user and the add the values to database in MongoDB. I am new to MongoDB. I have created a database and a collections ...
0
votes
0
answers
23
views
status code 500 while fetching Data from MongoDB using FastAPI
I'm writing a FastAPI endpoint from My MongoDB, when I try to fetch all the transactions in the collection I encounter code 500: internal server Error
Here is my code :
from fastapi import FastAPI, ...
0
votes
1
answer
26
views
How to avoid duplicates in nested document while updating
My data model looks like this screenshot, also shown here:
{
"_id": "619f6735336c8d0498bb5d00",
"name": "Class 1",
"department": "...
0
votes
0
answers
21
views
Trying to insert collection from mongodb to mysql table
mongodb contains 2 collection with 5 fields each:
{
"channel details": c,
"playlist details": p,
"video_ids": v_id,
"video details": v,
&...
1
vote
1
answer
38
views
Django pymongo update_many ''Cannot use the part (y) of (x.y) to traverse the element ({x: []})'}'
I have a collection like this with sample documents as:
[
{
"_id": {
"$oid": "64b28bafb2ea43dd940b920d"
},
"title": "Village Libraries&...
0
votes
0
answers
45
views
Find a precise field inside an object with an random key
Imagine this structure:
[...]
"items": {
"UUID1": { "fieldIwant": [...] },
"UUID2": { "fieldIwant": [...] },
"UUID3": { "...
0
votes
0
answers
16
views
SSL Handshake Error when writing AI analysis results to MongoDB Atlas from AWS lambda
I've been working on a project involving concurrent AI processing of around 100 videos using AWS Lambda. The results of this analysis are being written to a MongoDB Atlas database. For the most part, ...
0
votes
1
answer
19
views
pymongo raise OperationFailure while accessing data
I keep getting this error while using pymongo on my Atlas Database:
raise OperationFailure(errmsg, code, response, max_wire_version)
pymongo.errors.OperationFailure: Cannot do exclusion on field ...
0
votes
0
answers
27
views
pymongo.errors.OperationFailure: cannot add session into the cache
I have a non-sharded mongo cluster with maxIncomingConnections: 500. There were no application code changes but recently app is facing the below error. What is the reason for this error and how to ...
0
votes
2
answers
50
views
How Do I Generate A Random _Id for MongoDB In Python
On MongoDB the _Id field for some reason is always very similar, so similar that after 20 documents I cant insert more because the _Id will be the same. What I think is happening is MongoDB generates ...
0
votes
1
answer
23
views
BulkWriteError on insert_many when ordered=False
I have some records and am trying to insert_many using the following with pymongo:
db.collection.insert_many(records, ordered=False)
I know from this answer that setting ordered=False should allow me ...
1
vote
1
answer
57
views
SSL handshake failed in cosmosdb mongo api with python
I am trying to connect a database in azure cosmos that uses the Mongo DB API in Python. When I create the client, I get the SSL handshake failed error and I don't know how to solve it. I am aware that ...
0
votes
0
answers
11
views
Pymongo: Wait till every document is indexed
So guys,
I will try to make this as simple as possible:
Object:
...
status: str [open, close]
Flow:
1 - create object on mongo [status=open]
2 - update object on mongo [status=close]
3 - fetch ...
0
votes
0
answers
19
views
How to get collected document time MongoDB
In a MongoDB Atlas searchMeta aggregation:
from datetime import datetime, timedelta
results = my_collection.aggregate(
[
{
"$searchMeta": {
"...
1
vote
2
answers
43
views
Mongo DB / Python - Search DB for string but limit results to 1 of each item based on specified field
I am trying to search my MongoDB of products. The dataset has multiple of each product to record price over time. I would like to search for a phrase then limit the results to 1 of each UPC. My ...
0
votes
0
answers
27
views
MongoDB delete document using python
I am trying to delete document from MongoDB using python and there are error. I install pymongo and bson
from pymongo import MongoClient
from urllib.parse import quote_plus
from connections import ...
0
votes
0
answers
26
views
The Pymongo query with $gte returned different results compared to the client-side query
Here is the code by pymongo:
db['all_data'].find(
{"noCacheTime": {"$gte": 1691338596 }}
)
get two results.
But when I query the same in compass:
db.getCollection(&...
0
votes
1
answer
35
views
Attribute query search with case insensitive variable
Trying to do a query with something like this:
db.get_collection("collection").find({f"parent.{variable}": {"$exist": True}})
parent here would be an object and variable ...
1
vote
1
answer
36
views
MongoDB aggregation get values of multiple documents for last timestamp
This is a follow up question on my original post here: Improve MongoDB query in Python
My collection of hiking trails looks like this:
Each trail might be available multiple times for the same date ...
0
votes
0
answers
45
views
Mongo Vector Search - The heap is empty
What does it mean when pymongo raises an exception of type pymongo.errors.OperationFailure
Exception is:
The heap is empty, full error: {'ok': 0.0, 'errmsg': 'The heap is empty', 'code': 8, 'codeName':...
0
votes
1
answer
31
views
Improve MongoDB query in Python
I have a MongoDB database including hiking trails that I visualize in a Jupyter Notebook. Each trail has a start and destination and includes a timestamp when it was updated. So there are multiple ...
1
vote
1
answer
22
views
Can pymongo use to connect mongodb bi connector in python?
Can pymongo use to connect mongodb bi connector in python?
I had tried to connect a mongodb bi connector as the code below:
from pymongo import MongoClient
# Replace 'localhost' with the hostname or ...
2
votes
0
answers
31
views
How to connect a mongodb bi connector through python?
How to connect a mongodb bi connector through python?
Is pymongo can do it? If yes can please provide some example with the authMechanism PLAIN(LDAP)?
I had try to connect with the pymongo but seems ...
0
votes
2
answers
189
views
SSL handshake failed error when trying to connect to MongoDB with Python client
I'm trying to connect to my shared MongoDB cluster, but I keep receiving the following error: SSL handshake failed: ac-ascvkib-shard-00-02.hkzvmvh.mongodb.net:27017: [WinError 10054] An existing ...
0
votes
0
answers
36
views
E11000 duplicate key error from pymongo bulk upsert operation
mongodb: 3.4.24
pymongo: 3.13.0
using pymongo bulk upsert to insert/update documents in access_link collection, and get the following error:
{'writeErrors': [
{'index': 0,
'code': 11000,
'errmsg':...
0
votes
1
answer
35
views
How to Optimize Slow Aggregation with Large Collection in MongoDB?
EDIT ----
Here how I managed to optimized but is not enough yet.
it seems that the $setWindowFields stage is causing the slowdown
[
{
"$limit": 1
},
{
"...
0
votes
0
answers
16
views
Compute agg fields ignoring duplicates using PyMongo
My MongoDB dataset consists of dates and temperatures. It shows some duplicate dates, for example:
{date: "01-01-1970", "tmed": 12.4},
{date: "01-02-1970", "tmed&...
0
votes
0
answers
21
views
How to make motor(pymongo async driver) not load everything at the same time, but like in queue?
In my project on FastAPI i pass to motor generators of data. But when i send several requests to upload endpoint, motor don't insert not like first generator and then next and next, it's trying to ...