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.
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…
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…
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:
…
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}),…
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,…
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/
…
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…
If I have a document like this:
{
"_id" : ObjectId("5497b4281a78a9120872ca32"),
"title" : "Thrifty Kitchen",
"description" : "Damn ugly",
"products" : [
ObjectId("54990eeb1a78a91a5758af75"),
…
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 =…
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…
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…
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:…
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 =…
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",…