pymongo

How to catch an OperationFailure from MongoDB and PyMongo in Python.

I have been having a problem where after my mongodb connection to mongohq via pymongo goes idle for awhile (no queries), it will timeout. This is fine, but the connection the database is only created when the Django app is started up. It seems like it is reconnecting fine, but it needs to reauthenticate then. When the connection has died...

Why does my remote MongoDB connection require authentication on every query?

After fighting with different things here and there, I was finally able to get BottlePY running on Apache and run a MongoDB powered site. I am used to running Django apps, so I will be relating to that a bit in my question. The Problem Every time a page is loaded via BottlePY, the connection to the MongoDB database located on MongoHQ.c...

Performing regex Queries with pymongo

I am trying to perform a regex query using pymongo against a mongodb server. The document structure is as follows { "files": [ "File 1", "File 2", "File 3", "File 4" ], "rootFolder": "/Location/Of/Files" } I want to get all the files that match the pattern *File. I tried doing this as such db.collectionName.find...

How can I tell if there are more results from a query in MongoDB?

Is there a preferred way to query mongo with a limit and know whether there will be more results if I query for the next page with skip/limit? What I have been doing is asking for one more document than I need, slicing it off the end, and using the existence of that extra document to know whether another query will give at least one mor...

pymongo: a more efficient update

I am trying to push some big files (around 4 million records) into a mongo instance. What I am basically trying to achieve is to update the existent data with the one from the files. The algorithm would look something like: rowHeaders = ('orderId', 'manufacturer', 'itemWeight') for row in dataFile: row = row.strip('\n').split('\t') ...

PyMongo: group with 2d geospatial index in conditions returns an error

The error returned is: exception: manual matcher config not allowed Here's my code: cond = {'id': id, 'date': {'$gte': start_date}, 'date': {'$lte': end_date}, 'location': {'$within': {'$box': box }}} reduce = 'function(obj, prev) { prev.count++; }' rows = collection.group({'location': True}, cond, {'count': 0}, reduce) When I remove...

pymongo (python+mongodb) drop collection/gridfs?

Hello, Anyone know the commands to drop a collection of documents and also drop a gridfs database? ...

How to update mongodb collections.

My collection structure is: col1 = {'class':'12', 'roll':[1, 2, 3, 4]} Now I want to update the collection col1 to col1 = {'class':'12', 'roll':[1, 2, 3, 4, 5]} I added another roll number here. How to update this in pymongo. ...