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,355
questions
0
votes
0
answers
15
views
Push objects of given array to mongodb document's array if specific key values are not present
Lets say I have a document in mongo like
{
name: "abc",
manufacturer: "xyz",
...
history: [
{"condition": "new", "price": 150, ...
0
votes
1
answer
16
views
MongoDB field must be an array
Currently I have a collection with the following documents:
[
{
"_id": ObjectId("628e6bd640643f97d6517c75"),
"company": "bau",
"...
0
votes
0
answers
15
views
How to deal with OverflowError: MongoDB can only handle up to 8-byte ints in MongoDB?
I am using mongoDB for a side-project.
Trying to insert at document using pymongo I get this error:
'OverflowError: MongoDB can only handle up to 8-byte ints'
The issue is that my document has some ...
0
votes
1
answer
20
views
How can I get specific field value with array nested filter in MongoDB?
After I filtered nested array values then I added "$project" query for selecting specific fields.
I want to get "new_yn" field values outside of the nested array but I only got id ...
-1
votes
0
answers
16
views
How i can use unionWith in pymongo?
I need to use unionWith in python pymongo . in Mongodb compass is
db.collection.aggregate([{ $unionWith:"A"},
{ $unionWith:"B"},
{ $unionWith:"C"},
{ $unionWith:"D&...
0
votes
0
answers
11
views
How to make a histogram with MongoDB in pymongo?
I want to make a histplot/histogramm which shows the ages of the customers. I use MongoDB with python/pymongo. How can i do this?
I have these objects:
{"name": "martin", "age&...
0
votes
1
answer
23
views
MongoDB driver to support most Django functionality
As per the project requirment, I have to use Django + MongoDB. I am super new to Django (not good in Django's ORM too) but have good experience with MongoDB. My project is about storing a lot of ...
0
votes
1
answer
28
views
How to insert data on last item of an inner array in MongoDB
I am trying to insert data in the last element of an array in MongoDB. insert in the first element works using the 0 operator, but I'm confused about how to insert in the last element. To explain it, ...
0
votes
0
answers
11
views
How to get PyMongo's bson to decode everything
I'm trying to get some data stored in a .bson file into a jupyter notebook.
Per this answer and this answer, the accepted answer is basically to use the bson module from PyMongo, and then the ...
0
votes
0
answers
10
views
PyMongo with object relation model
I'm using pymongo in a project as mongodb interface in python. Is there any way to define structured classes as models and pass them as objects to pymongo?
As a matter of fact, I mean something like ...
0
votes
0
answers
22
views
pymongo - How to check basic statistics?
I want to see the statistics of all data in a collection. I want the same result as the describe function in Python Pandas (statistics on multiple columns, not just one column). Using aggregate by ...
1
vote
1
answer
19
views
how to use aggregate with filter inner array inside $project
Currently I'm using mongodb to store data about my forms and responses, when I using a find in my collection the following data is returned:
[
{
"_id": 1,
"forms&...
0
votes
0
answers
20
views
MongoDB : extremely huge log file?
I have set up MongoDB (on windows) a while ago to listen to WebSockets. Recently, I was checking the size of the dataset I had collected so far. The total size of my data folder where the collections ...
0
votes
2
answers
22
views
TypeError: Database.__init__() missing 1 required positional argument: 'col'
118 db = Database(DATABASE_URL, BOT_USERNAME)
119 mongo_db_veritabani = MongoClient(DATABASE_URL)
120 dcmdb = mongo_db_veritabani.handlers
Exception has occurred: TypeError
Database.init() missing 1 ...
0
votes
1
answer
24
views
I Made Tow function in pymongo but the out but that i want is different from i get from the function any ideas how can i fix it?
Funtion that save Close,Symbol, Timeframe
def Save_(self,collection,symbol,price,TF):
db = self.get_db('MTF')[collection]
B = {'ts':time.time(),"Symbol":symbol,
...
0
votes
1
answer
12
views
MongoDB: Get keys and values as separate arrays with new keys
I have the following MongoDB collection.
{
"timestamp": "10:05:12",
"value": 100
},
{
"timestamp": "15:07:01",
"value": 120
}...
0
votes
1
answer
34
views
Find only specific key from mongodb using pymongo
I have written this code and I want to check only for a key named Virtual_Machines. I have data in the following form. I only want to check if Virtual_Machines is there then don't upload data again.
...
-3
votes
0
answers
28
views
How do I create an if statement with MongoDB
So I am creating a login system and want it to search for usernames and passwords within my cluster and if a username is found and the entered password matches it calls a certain function, however I ...
0
votes
1
answer
23
views
How to select and return just the inner objects in mongodb
I would like to retrive just the responses from a single form of the document below, I'm using pymongo, so I'm using the .find() method.
Every query I do Al other fields are returned too, So I'm ...
0
votes
0
answers
6
views
i don't get mongodb collection shard key with pymongo
i need to copy db meta to anthoer , i have done copy index, but i couldn't get the shard key of colleciont , so what should I do ?
can you give me a example ?
cnn = pymongo.MongoClient(mongo_uri)
...
0
votes
1
answer
17
views
'join' two MongoDB collections on a key, without creating a nested structure
I'd like to 'join' two MongoDB collections on a key, without creating a nested structure.
Code:
# Init client
client_mongo = pymongo.MongoClient(
host="mongo", port=27017, username="...
0
votes
2
answers
35
views
Set up mongodb _id to firebase uid
I'm new to asking questions in Stack overflow.
I'm implementing an application that it's using Firebase Auth for users login, logout and delete account and mongodb with python (pymongo) to manage the ...
0
votes
0
answers
22
views
Aggregate slow on $lookup
I have two collections (Rec22, Rec23) having 120K documents in each.
Rec22
{ "_id" : ObjectId("6284a6b84b171c659ec86561"), "22" : 423 }
{ "_id" : ObjectId("...
0
votes
0
answers
34
views
Mongodb data schema validation errors
In my flask app I am trying to insert data into a mongodb database and validating the data, but I keep getting validation errors and I can seem to be able to locate why this is the case. I am new to ...
0
votes
0
answers
15
views
Pymongo and Atlas server selection timeout can't connect both with tls or not
I've installed pymongo using python3 -m pip install pymongo[srv].
I'm trying to connecting to my atlas database using the following python3 code:
#!/usr/bin/env python3
import logging
import sys
from ...
0
votes
0
answers
7
views
Error to get data: single positional indexer is out-of-bounds while executing the script
The actual script gets data in a range of dates from January first to today's date with e while loop, the script is working up to a certain moment where i got the error :
Error to get data: single ...
0
votes
1
answer
39
views
MongoDB/PyMongo: upsert array element
I have the following document:
{'software_house': 'k1',
'client_id': '1234',
'transactions': [
{'antecedents': 12345,
'consequents': '015896018',
'antecedent support'...
-2
votes
0
answers
14
views
How to write Inner Join condition in MongoDB with multiple columns
I was trying to join two collections using multiple columns. I was exactly looking for an inner join output. Can some one help me on getting the query in MongoDB
0
votes
0
answers
29
views
Motor/PyMongo connection timeout with AWS DocumentDB
I have used Python's Motor library to connect to an AWS DocumentDB (MongoDB) instance. Motor uses PyMongo behind the scenes.
This was all working fine, but suddenly I have been getting a connection ...
-1
votes
1
answer
26
views
Iterate over python dict based on a csv column which is grouped
I have attached an csv file. I have written a python script which reads the csv file and iterates over a data frame and process the contents of csv and insert it into mongoDB.
Right now, all data is ...
0
votes
0
answers
5
views
mongoengine model field to store list of string or None
I am using mongoengine ORM with FasiAPI.
I wanted to store a list like this ['spraying', 'deweeding', None, None]
I am currently using this
ACTIVITY_TYPE_CHOICES = ('spraying', 'broadcasting', '...
0
votes
0
answers
23
views
insert nested fields in mongodb collection using python
I am new to mongoDb and looking for some help in inserting nested values to mongoldb collection using python.
I Have a collection in mongoDB called(test) that already has a number of fields in it.....
0
votes
1
answer
19
views
Pymongo: update document only if value of a field matches a provided value
Is it possible to update a document based on the condition that the value of a field in that document matches a value that I provide?
I can easily do this in two steps but was wondering if there was a ...
0
votes
1
answer
43
views
mongodb command very slow
I have 3 documents like this:
{
_id: ObjectId("..."),
_details: {
_session: ObjectId("example_1"),
},
{
_id: ObjectId("..."),
_details: {
_session: ObjectId("...
-1
votes
1
answer
20
views
MongoDB get intersection from result set
I am new to MongoDB.
I have pymongo to access mongodb.
The data is in this format
{
shop:"shop A",
city:"xxx",
electronics:["phone","laptop","television&...
0
votes
0
answers
24
views
How to make a linux service scalable in AWS
Im using the mongodb change streams with pyMongo to feed amazon kinesis data stream with the database logs. This is the code of the python script that im running as a service in an EC2 instance:
...
0
votes
2
answers
46
views
Speed up MongoDB Query Response | Discord Bot
I didn't think this would be an issue, but as the database I am using continues to grow, I've noticed that the responses from my program are getting slower and slower (which makes sense, more stuff to ...
0
votes
0
answers
18
views
pymongo connection string error but works in mongdb driver .net and mongosh
I have a connection string that I am able to connect via MongoDB.Driver .NET and mongosh but when I am using pymongo - throws the error below.
Here is what I am using for pymongo
from pymongo import ...
0
votes
2
answers
26
views
Converting values in dictionary in to another dictionary using python
I have a set of dictionaries with keys and values i need all the values as a separate dictionary
print(i)
O/P:
{'type':a,total:3}
{'type':b,total:2}
{'type':c,total:5}
{'type':d,total:6}
But now the ...
0
votes
1
answer
14
views
changing format using pymongo
This is the MongoDb query which i was using in pymongo to get the value
query = [{"$match": {"scheduledAt": {"$gte": startTime, "$lt": endTime}}},
...
0
votes
1
answer
24
views
How can I get a right query result in MongoDB (specially nested array)?
I guessed when I run that MongoDB Query then I can get only filtered port_code 'http_https' data but it wasn't. All data is selected.
How can I fix my Query? Would you give me some guides?
Query
{'...
0
votes
0
answers
16
views
Optimise Pymongo query time
I am running a query on mongo db and looking for a solution(s) to optimise the time taken.
my query is like collection.find({'nameId':989080880,'Date':{'$gte':startDate}})
what I did is as below
pd....
0
votes
1
answer
60
views
Collection' object is not callable. If you meant to call the 'update' method on a 'Collection' object it is failing because no such method exists
I am trying to save a record into mongo db using pymongo. I have the script to update the collection if it exists or insert one record. This snippet works when run interactively, but when I try to do ...
-1
votes
0
answers
31
views
Connect mongodb from pymongo inside a docker container
I am running an application where each of its component running inside separate
containers.Now I have mongodb running locally,it's not part of a container.How
can I connect the mongodb from inside of ...
0
votes
1
answer
36
views
Inserting specific columns of csv file into mongodb collection using python script
I have a python script to insert a csv file into mongodb collection
import pymongo
import pandas as pd
import json
client = pymongo.MongoClient("mongodb://localhost:27017")
df = pd....
0
votes
1
answer
55
views
Efficiently upsert thousands of records to mongodb
We have a database containing around ~20 Million records with an indexed field order_id.
Every day, after each hour, we receive an incremental update, starting from ~2K and growing to ~50K records ...
-2
votes
0
answers
26
views
PyQt & PyMongo - AttributeError: 'bool' object has no attribute 'ui'
Im trying to seperate the code out to keep it neater and easer to follow and understand. Im just not getting why I keep getting this error. Any help would be appreciated
File 1
from PyQt5.QtWidgets ...
0
votes
0
answers
27
views
Python Datetime.datetime is not giving me results in mongodb aggregate
startTime and endTime is a datetime object, same query gives me the desired results on Mongodb Compass.
pl = [
{
"$match": {
"clientId": id_,
"Date": {
...
1
vote
1
answer
24
views
pymongo 4.1.1 and mongoengine version compatibility
Updated to pymongo 4.1.1 and upgraded mongoengine to 0.24.1 but received the following error:
pymongo/collection.py", line 1610, in find
return Cursor(self, *args, **kwargs)
TypeError: ...
1
vote
0
answers
28
views
MongoDB query works in compass, but not in python
I've a collection, roughly 100M documents. When I'm trying out this aggregation in compass:
aggregate([
{
'$match': {
'type': 'myType'
}
...