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.

0
votes
0answers
3 views

Pymongo bulk_write with UpdateOne throwing Scanned Objects / Returned has gone above 5000 alert

I'm having aroung 190 millions records in my collection, it has compound index {"company":1, "date":-1, "datatype":1} and it doesn't have any duplicates documents. Every month I'm upserting around 20 ...
0
votes
0answers
8 views

How to use aggregate functions in pymongo (like for finding average rating and counting)?

I am specifically focusing on using avg and sorting according to resulting values in pymongo. Any help is appreciated?
-1
votes
0answers
15 views

Python bson: How to create list of ObjectIds in a New Column

I have a CSV that I'm needing to create a column of random unique MongoDB ids in python. Here's my csv file: import pandas as pd df = pd.read_csv('file.csv', sep=';') print(df) ...
0
votes
0answers
10 views

pymongo - mongodb+srv “dnspython must be installed” error

I am trying to connect MongoDB from Atlas But I encountered "dnspython must be installed error". My mongo uri (mockup): mongodb+src://abc:123@something.something.com/admin?retryWrites=True My ...
0
votes
1answer
10 views

How to add a field in fs.chunks collection in MongoDB using Pymongo?

I am using GirdFs to store images in my local directory to MongoDB Collection. from pymongo import MongoClient from imutils import paths import gridfs client = MongoClient("127.0.0.1", 27017) db = ...
0
votes
0answers
5 views

ServerSelectionTimeoutError with flask pymongo

I have set up the basic flask APP in my local machine that connects to the MongoDB at the backend fetch data and show it on the browser, now the issue is when I try and execute the code at localhost:...
0
votes
0answers
12 views

Query Objects within a Nested Array MongoDB [duplicate]

This has been marked as duplicate. However, the answer marked as duplicate is one I've already looked at, and it hasn't helped me. Please read on. In MongoDB, I'm trying to return filtered results ...
1
vote
1answer
14 views

Using $natural sort in pymongo - MongoDB [duplicate]

I understand that using the $natural sort in MongoDB can improve disk throughput as the cursor will read sequential records rather than jumping around. However when I try to use this SO example or ...
0
votes
1answer
22 views

How to create index of array in pymongo [duplicate]

I have data like: { title : "Moby-Dick" , author : "Herman Melville" , published : 1851 , ISBN : 0451526996 , topics : [ "whaling" , "allegory" , "revenge" , "American" , "novel" , "nautical" , "...
0
votes
0answers
10 views

PyMongo: all values from columns MongoDB

I have database in MongoDB. How can i get all values from all columns in one of my collections? Need to create dictionary to write this values.Because in future i want to compare values from 2 ...
0
votes
1answer
12 views

Python PyMongo / Displaying Output as a plain String

I have a quick question: I have a MongoDB Database with a collection of dummy data. I used the follwoing code to display all documents within my collection (in this case FlightNo and Terminal): def ...
0
votes
0answers
22 views

Concat in query throwing unhashable type error

I am getting the error TypeError: unhashable type: 'dict' when I try use $concat in my pymongo query My schema: {'tags': {'variables': [{'value': '3x9', 'var_name': 's'}, {'value': ...
0
votes
1answer
38 views

Serialising data to pymongo; how to handle a setter with a property?

I'm serialising __dict__ to mongo, but I want to intercept setting laden t. How can I do that without having to rename the attribute to _laden in order to use a property with a setter? I know that I ...
0
votes
1answer
14 views

MongoDB merging documents

My collection has the following form: { "_id" : ObjectId("5bc5dec478f5e2032d37e7c2"), "" : 1, "C_ID" : 1, "I_ID" : 7503672, "TIMESTAMP" : "2018-03-12"} { "_id" : ObjectId("4bc5dec478f5e2032e37e7c2"), ...
0
votes
1answer
31 views

Query tangled array in Pymongo

I am trying to query a very tangled collection. The schema: {'tags': {'variables': [{'value': '3x9', 'var_name': 's'}, {'value': '12:00AM', 'var_name': 'x'}, ...
0
votes
1answer
19 views

Untangle dictionary inside list

I need some help figuring out this complicated list. I am trying to print just the var_names. I have created a list from a mongo collection so that I can use it as a jSON object later. List format: ...
3
votes
1answer
59 views

How to convert a field, which is an array of objects with K-V pairs to array of arrays with only values?

I have a collection in MongoDB which has a field called "geometry" with latitude and longitude like this : { "abc":"xyz", "geometry" : [ { "lat" : 45.0, "lng"...
0
votes
1answer
10 views

Pymongo OperationFailure: Index with name: timestamp_1 already exists with different options

I came across this problem when I tried some scraping code. I defined a class MongoCache to cache the html pages: class MongoCache: def __init__(self, client=None, expires=timedelta(days=30)): ...
0
votes
0answers
18 views

Pymongo- Check if the document is inserted properly when insert_one function is used

I'm using insert_one function in pymongo to insert a single document to a collection. And the function returns me an instance of pymongo.results.InsertOneResult From the pymongo.results....
1
vote
1answer
23 views

inserting multiple rows into mongo

I am having a pandas data frame like below :- I am using below code and inserting the data in mongodb:- mydb = conn["mydatabase"] mycol = mydb["test"] x = results_df["user"] # result_df is the data ...
0
votes
0answers
17 views

telegramm bot and pymongo. How do I get the last value sorted by time?

I try to write a telegram bot with the ability to get data from mongodb, I have many documents of the kind: { "_id" : ObjectId("5ac02101895ff10e40afb698"), "DeviceTime" : ISODate("2018-03-...
-1
votes
0answers
11 views

in python syntex of update in pymongo with 'arrayFilters'

Can anybody tell me what is the syntax of update in pymongo with 'arrayFilters'? I have applied in my code but it is giving me an error. "TypeError: upsert must be True or False".. My code is as ...
0
votes
0answers
14 views

Pymongo on raspberry pi 3 wait too much to raise an error

I have an issue with pymongo on raspberry pi 3. The thing is when I run the script normally (I mean, I have internet connection and database connection, so there is not problem writing on database) I ...
0
votes
1answer
21 views

Pymongo auth fail when trying to loop on mongo cursor

I managed to get this working. I'm trying to loop over the documents in the response from a query to a remote mongo. I can connect to mongo and run the query with a cursor object coming back. However ...
0
votes
0answers
23 views

inserting raw python dictionary into mongodb

I have raw python dictionary like below which is having billions of key value pair test_dict1={'2605bad44c2140099dd20da3c11b92f9@fnwpvivoxcom': '1', 'a26cc4136f834957ad4f8e861d0c29a3@fnwpvivoxcom': '...
0
votes
0answers
13 views

How to make ObjectId serializeable to JSON in Python? [duplicate]

I want to create a Web API which transmits data in JSON format and i want to use MongoDB's ObjectId as my data ID. How should i make ObjectId serializable to JSON so that when i execute the following ...
0
votes
1answer
37 views

Explain why results from mongo are being returned in reverse ObjectId order?

I have a list of news article items which I am tagging for entities, and topic tags. my query db["fmetadata"].find({'$and': [{'$text': {'$search': 'apple trump'}}, {'$or': [{'entities': {'$...
2
votes
1answer
28 views

MongoDB: multiprocessing update and '$inc' operation

I have a question on doing $inc update in MongoDB concurrently. In the manual page of UpdateOne and findOneAndUpdate, the subtlety of applying concurrent upsert was mentioned, and using a unique index ...
0
votes
0answers
15 views

unit-test for async-await function

How should I write this async-await (sample function) for unit-testing? This part of code includes to drop the collection from mongodb database by using motor-tornado! import motor import traceback ...
0
votes
0answers
25 views

How to send requests to MongoDB using JavaScript (front-end app) with Authentication?

Is there a tutorial or a procedure that explains how should I connect to a MongoDB database using JavaScript, AJAX and jQuery with authentication? Using PyMongo in Python, I am able to give the ...
0
votes
1answer
15 views

Authentication failed error in Python script to connect MongoDB server using pymodm

The MongoDB server is hosted in a docker container. Created a super user with root permission to login using username and password. Using pymodm to connect to MongoDB server from Python script. I'm ...
0
votes
0answers
13 views

How to handle PyMongo/MongoEngine AutoReconnect?

When I used MongoEngine to query over 100K documents iteratively in a collection. It usually ended up with "pymongo.errors.AutoReconnect: [Errno 54] Connection reset by peer". I've already checked ...
0
votes
0answers
11 views

Can't Connect To MongoDB With Raspbian Linux

I am wanting to use PyMongo on raspbian Linux, however, I can't seem to connect to the online service. I have installed pymongo. In python, my connection string is mongodb+srv://Username:Password@...
-2
votes
0answers
24 views

Use value from one query in another using pymongo

I am using pymongo with django. I want to use the result of one query in another. This is what I have so far. But I am getting errors when I try userInfo = myUL.find( { 'action': "c_r" , '...
0
votes
1answer
33 views

how to update particular json object inside json arry in mongodb

{ "userId" : "111", "userName":"abc", "skills":[ { "DomainName" : "Application", "skillName" : "Python", "months" : "2", "level" : "8", "...
2
votes
1answer
37 views

Creating $elemMatch query with multiple $regex clauses in python and mongo

I am implementing this tutorial How to Speed-Up MongoDB Regex Queries by a Factor of up-to 10 and I am using the query specified at the end db.movies.find({ $and:[{ $text: { $search: "...
0
votes
0answers
17 views

How to upsert in mongodb?

I am trying to do an upsert in mongodb as below and running into below error?I looked at other posts pymongo typeError: document must be an instance of dict, bson.son.SON, bson.raw_bson....
2
votes
1answer
31 views

How to do a case-insensitive regex search of mongodb? [duplicate]

I am trying to read data from mongodb database as below and running into couple of issues,can anyone provide guidance? 1.Running into below error,how to fix this? 2.Is there a way to do a case-...
1
vote
0answers
37 views

How to read json file containing ObjectId and ISODate in Python?

I want to read a JSON file that contains ObjectId and ISODate. JSON DATA : { "_id" : ObjectId("5baca841d25ce14b7d3d017c"), "country" : "in", "state" : "", "date" : ISODate("1902-01-...
0
votes
0answers
20 views

MongoDB Only Logging Documents In Localhost

[Answered] I have started using MongoDB, and it works great to an extent. When I access Compass, if I sign in as the localhost port 27017; I can see all my documents. However, I ideally want it to be ...
1
vote
1answer
41 views

Writing a MongoDB query to filter based on a reference's attributes?

Let's say I have a set of documents called "dog," a set of documents called "owners," and a reference to an owner from within each dog document. For example: dog1: {"_id": "abcdef0123456789", "name"...
0
votes
0answers
27 views

How to flatten a nested json and apply match condition using pymongo

Please find my code below results = pricing_data.aggregate([{ "$match": match }, { "$unwind": "$states" }, { "$unwind": "$states.coverages" }, { "$unwind": "$states.coverages.mods" },...
0
votes
0answers
27 views

$group returning empty rows when I use aggregate

I want DISTINCT rows with my query. I am getting total instead of distinct rows. I tried $group but that is returning empty rows Query: pipeline = mycol.aggregate([ { '$lookup': {'from': "...
-1
votes
1answer
20 views

MongoDB -Match condition is not working properly

I just need to fetch the data from the mongodb using a condition Condition is i want to get all the data from the mongodb till today .Please see my code below match = {[{"lastUpdatedTs": {"$lte": ...
0
votes
0answers
25 views

How to insert an ordered dict to mongodb using pymongo?

I'm using python 3.5.2 and pymongo while trying to store a dict to mongodb data = {'A':1,'B':2,'C':3} test = {'A':data['A'], 'B':data['B'], 'C':data['C']} x = mycol.insert_one(test) #mycol is the ...
0
votes
1answer
31 views

Pymongo not able to connect to the database: pymongo.errors.ServerSelectionTimeoutError: connection closed

I want to read the collection through pymongo but I am getting the following error: Traceback (most recent call last): File "C:/Users/GSingh/PycharmProjects/MC/quizQuestionAnswers.py", line 21, ...
0
votes
0answers
27 views

Pymongo raises “pymongo.errors.AutoReconnect: connection closed” when performing a big read query after a big insertion process

We have several Python 3.6 scripts performing web scrapping and saving the results in a mongo collection (mongo server version 3.6.3 and pymongo 3.4.0). These scripts are executed several times a day ...
0
votes
0answers
17 views

pymongo $lookup puts everything returned into one object

The following lookup is supposed to combine the recipe info with the user info, where the recipe author matches the user _id. The lookup does return each recipe and adds username[] to each recipe. ...
0
votes
1answer
41 views

How to check if the document is empty by pymongo?

I tried to prevent pymongo.errors.InvalidOperation: No operations to execute after getting aggregate function's result. However, the way I used still shows pymongo.errors.InvalidOperation: No ...
0
votes
1answer
13 views

how do i iterate a cursor in pymongo

i am currently working on a project and i have created two collections in my mongodb . i want to be able to get a particular field out of the collection here is the code app = mongo.db.apps find_app =...