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.

PyMongo is the official Python driver for MongoDB created and maintained by MongoDB, Inc.

Note: Since PyMongo 3 is not backward compatible with PyMongo 2 (refer to the changelog for details), you should specify the version you're using in the body of your question.

Documentation

Related Links

Related Tags

6819 questions
2
votes
1 answer

Pymongo issue in a python project

I have installed pymongo, and when I start a new project and I write import pymongo Python shows me the next error. Python version: 3.4.3 Error code Traceback (most recent call last): File "TestMongoDB.py", line 3, in import…
Ismael Moral
  • 722
  • 1
  • 9
  • 35
2
votes
2 answers

Do file size requirements change when importing a CSV file to MongoDB?

Background: I'm attempting to follow a tutorial in which I'm importing a CSV file that's approximately 324MB to MongoLab's sandbox plan (capped at 500MB), via pymongo in Python 3.4. The file holds ~ 770,000 records, and after inserting ~ 164,000 I…
Chuck
  • 998
  • 8
  • 17
  • 30
2
votes
1 answer

pymongo update_one syntax error

have a collection in mongodb called 'collection' and I need to do and upsert using pymongo. collection.update_one({'_id': workflowID}, { '$set': {'repop': repop}, {'data': workflow__list()__} }, upsert = True, multi = False) but I get…
Connor G.
  • 23
  • 1
  • 4
2
votes
1 answer

How to keep appending subdocuments in MongoDB?

I am trying to do a bulk insert in MongoDB using PyMongo. I have millions of product/review documents to insert into MongoDB. Here is the structure of the document: { "_id" : ObjectId("553858a14483e94d1e563ce9"), "product_id" :…
Randeep
  • 99
  • 1
  • 1
  • 4
2
votes
1 answer

Scrapy Mongodb Connection

I am scraping the data using scrapy.Now i want to store the data in mongo db for that i install pymongo but i am unable to connect to the databse Here is my code for settings.py ITEM_PIPELINES =…
Sameer Shaikh
  • 273
  • 1
  • 9
  • 21
2
votes
1 answer

How to change mongodb default cleanup time for TTL index?

I want to set TTL around 2-3 months so its clearly infeasible to check after every 60 sec for TTL indexex. I want to reduce overhead by checking TTL once in a day. Is there any way to manually/programmatically define this time?
Shailesh
  • 367
  • 1
  • 5
  • 15
2
votes
2 answers

Cursor id not valid at server even with no_cursor_timeout=True

Traceback (most recent call last): File "from_mongo.py", line 27, in for sale in pm.events.find({"type":"sale", "date":{"$gt":now-(_60delta+_2delta)}}, no_cursor_timeout=True, batch_size=100): File…
user37203
  • 676
  • 5
  • 21
2
votes
3 answers

mongodb: counting unique array elements

I'm trying to get an overall count of array elements across an entire collection. The input collection is db.test.insert( { "_id" : 1, "item" : "A", "hx" : [ { "label" : "new" , "price" : 10.99 , "category" : "P1"} , …
user2105469
  • 1,413
  • 3
  • 20
  • 37
2
votes
3 answers

Deleting specific record from an array nested within another array

I have a MongoDB record as follow: "id": 1, "Tasks": [ { "description": "BLAH", "Tags": [ { "Name": "test", "tagID": "YRG+crq3SJucvlUwTo/uSg==" }, { …
user94628
  • 3,641
  • 17
  • 51
  • 88
2
votes
2 answers

Insert into MongoDB retuns cannot encode object

I'm doing a rather simple insert into a local MongoDB sourced from of a Python pandas DataFrame. Essentially I'm calling datframe.loc[n].to_dict() and getting my dictionary directly from the df. All is well so far until I attempt the insert, where…
Thatch
  • 157
  • 1
  • 2
  • 11
2
votes
1 answer

how to update subdocument in nested array of subdocuments

Using mongodb with pymongo, I have the following document: { "_id" : ObjectId("5515d697453d9a1975123e0b"), "Study_Attributes" : [ { "value" : "183", "tag" : "height", "unit" : "cm" }, …
shaw2thefloor
  • 600
  • 5
  • 20
2
votes
1 answer

find_and_modify with upsert using Python-EVE

There is common use case when you need update or insert. For instance: obj = db['data'].find_and_modify( { 'Name': data['Name'], 'SourcePage': data['SourcePage'], }, data, upsert=True …
alexander_ch
  • 356
  • 5
  • 12
2
votes
1 answer

Updating a value of dictionary in list of dictionaries in a collection using PyMongo

The collection structure that I have is as follows: defaultdict( lambda: { '_id' : None, 'stuff' : [defaultdict(lambda : 0)] }) I am trying to initialise a list of dictionaries that I'll keep on updating in a way that if a…
Animesh Pandey
  • 5,900
  • 13
  • 64
  • 130
2
votes
1 answer

PyMongo returns an empty result set when a MongoDB client returns correct results

I have a simple MongoDB collection that I am accessing using PyMongo in my Python script. I am filtering the query in Python using the dictionary: { "$and" : [ { "bettinginterests" : { "$elemMatch" : { "runner.name" : "Jailhouse King" } } }, …
Brett
  • 11,637
  • 34
  • 127
  • 213
2
votes
2 answers

how to write mongodb query in python for db.collection.group()

I am working on a MongoDB query db.BH.group({ "key": { "AccountId": true, }, "initial": { "count": 0 }, "reduce": function(obj, prev) { if (true != null) if (true instanceof Array) prev.count += true.length; else…
abhyuday
  • 126
  • 1
  • 9