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
2 answers

Concurrency in MongoDB

I'm using the collection requests as a queue that multiple clients read from concurrently. Each client will read one document at a time from requests and then remove it from the collection. Can I ensure that each document is read and processed by…
rgrasell
  • 99
  • 2
  • 11
2
votes
1 answer

How to query as the count of hitting element in a list on a field which is a list in Mongodb using Python?

Given the following documents in the ariticle collection: { _id: 1, words: [ "Apple", "IT", "Company", "IOS" ] } { _id: 2, words: [ "Google", "Android", "Search Engine","Company" ] } Now, I wanna to query on the words field to get the documents…
user3872279
  • 121
  • 2
2
votes
1 answer

Get opcounters by database

I have a monitoring script that looks something like this client = pymongo.MongoClient() for database in client.database_names(): iterator = client[database].command({"serverStatus":1})["opcounters"].iteritems() for key, value in iterator: …
Jacklynn
  • 1,503
  • 1
  • 13
  • 23
2
votes
2 answers

In MongoDB, is db.collection.find() same as db.collection.find().sort({$natural:1})?

I'm sure this is an easy one, but I just wanted to make sure. Is find() with some search and projection criterion same as applying a sort({$natural:1}) on it? Also, what is the default natural sort order? How is it different from a sort({_id:1}),…
gravetii
  • 9,273
  • 9
  • 56
  • 75
2
votes
3 answers

'str' object does not support item assignment when inserting to pymongo collection

RHEL 6.5, python 2.6.6 I'm trying to write decoded messages in to a MongoDB collection. The "decoded message" is received in the form of a dictionary. Within that dictionary the keys are all strings, and the values can be strings, integers,…
John Dibling
  • 99,718
  • 31
  • 186
  • 324
2
votes
2 answers

Flask/PyMongo - Initialize pymongo at the top of the app

I'm trying to scale up my first Flask app and am not understanding the structure needed to use a pymongo db in multiple modules. For example, here is my new structure: run.py app/ ├── __init__.py ├── forms.py ├── static/ ├── templates/ └── views/ …
Scott
  • 3,204
  • 3
  • 31
  • 41
2
votes
1 answer

MongoDB query optimization for large documents - dataset - query stuck

I would like to have an opinion from MongoDB experts as what mongodb query optimization / feature options, I can apply to make read query faster for such large collection of documents (datasets) to be available in one go (find query). May be someone…
Navi
  • 109
  • 1
  • 2
  • 9
2
votes
1 answer

Pattern to resolve mongoDB references

If I have a document like this: { "_id" : ObjectId("5497b4281a78a9120872ca32"), "title" : "Thrifty Kitchen", "description" : "Damn ugly", "products" : [ ObjectId("54990eeb1a78a91a5758af75"), …
Scott
  • 3,204
  • 3
  • 31
  • 41
2
votes
0 answers

How to improve performance of Pymongo aggreation

I have a Mongoengine model representing one entry of a distance matrix: class Distance(db.Document): """ An instance of the distance matrix. """ orig = db.ObjectIdField(required=True, unique_with='dest') dest =…
Emanuel Ey
  • 2,724
  • 5
  • 30
  • 38
2
votes
2 answers

How to use '*' in Mongodb?

I have 2 variables, sent from ajax, like name and age, their default value is '*'. when name and age are set, like name = 'a', age = 20, I can query in mongodb(pymongo): info = list(db.test.find({'name': name, 'age': age})) But there is time age or…
lzhmqq
  • 35
  • 4
2
votes
2 answers

Remove an array element from an array of sub documents

{ "_id" : ObjectId("5488303649f2012be0901e97"), "user_id":3, "my_shopping_list" : { "books" : [ ] }, "my_library" : { "books" : [ { "date_added" : ISODate("2014-12-10T12:03:04.062Z"), "tag_text" : [ …
Steve jobs
  • 43
  • 4
2
votes
1 answer

High insertion times in mongoDB

We have a collection which feeds from several (3) UDP servers which get a entry and puts it into mongodb. I've started to check profile on mongodb and witnessed that some time (most of the time it's fine) I get high (~5000) for insertion. There are…
shevski
  • 1,012
  • 1
  • 10
  • 32
2
votes
1 answer

Best way to sum array sizes fields in mongoDB

I have documents with an array field and I need to sum the sizes of this array across all documents. I'm using python --> PyMongo. In a nutshell, applying the aforementioned query to this set of documents should return 6: {_id: a, array:…
Alberto Coletta
  • 1,563
  • 2
  • 15
  • 24
2
votes
1 answer

Correct way to call aggregate function

I'm using pymongo version 2.7.2. I just want to count occurrences by name matching by Hostname. I don't want to use map/reduce. I want to do it through aggregate function. Executing this query: "Counting by name matching by Hostname" cursor =…
2
votes
1 answer

PyMongo query on Aggregation

I have written a query in mongodb using aggregation which is working fine but somehow it is not working properly in my python code with pymongo. Please advice how to rectify. Mongo query: db.flights.aggregate([ { $match: { origin:"ATL",…
miku
  • 95
  • 1
  • 2
  • 11
1 2 3
99
100