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

Aggregate totals for Multiple Keys

Given below the following data structure of a document: { "_id" : x, "device_model_id": x, "device_os_id": x, "device_status_id" : x, } I would like to group the data by device_status and device_os: {u'ok': 1.0, u'result': [ { …
Ryan
  • 2,167
  • 2
  • 28
  • 33
2
votes
1 answer

repair mongodb database using pymongo

How can I repair a specific mongodb database using "pymongo", similar to "db.repairDatabase" shell command? My goal is to get the freed space back to OS after I drop a few collections in DB, which requires that I repair the DB. Thanks!
Moji
  • 121
  • 4
2
votes
1 answer

Unable to create a collection through insert() in pymongo for mongodb and an attribute error

I am trying to input document into my mongodb test database in colors collection which is not there but it should create one if one not exists. My following code does not show any new collection named as "colors" and as far as I understand the…
Umer
  • 97
  • 1
  • 12
2
votes
1 answer

What happens to a pymongo cursor when all its elements have been iterated?

I wanted to use pymongo to get an array of entries from my database. It seems to return a "cursor" instead. I don't know what that is. all_nodes = pymongo.MongoClient("mongodb://localhost")["provemath"]["nodes"].find(None) print('ALL…
mareoraft
  • 3,474
  • 4
  • 26
  • 62
2
votes
1 answer

mongodb: replace an element in an array with one or more elements

given a collection such as : { _id: 1, fruits: [ "apples", "pears", "oranges", "grapes", "bananas" ], } { _id: 2, fruits: [ "plums", "kiwis", "oranges"], } { _id: 3, fruits: [ "plums", "kiwis", "oranges", "bananas", "apples"…
gnub
  • 193
  • 2
  • 11
2
votes
0 answers

How to store emojis as unicode in MongoDB?

I'm downloading tweets with specific words included using the Streaming twitter API and analysing with python using pymongo; I get the results back in json format. I'm looking to search with specific emojis as well as words. When I print the output…
2
votes
1 answer

How to use $in with a Regular Expression with Pymongo

I am trying to aggregate a collection in mongodb based on $in which tries to get the aggregate data from all the documents whose Log_Dir contains '/route_sanity/' in it somewhere in the path. Surprisingly this query doesnot works with pymongo.…
2
votes
1 answer

What do the PyMongo docs mean by "sub-collection"?

This page in the documentation says you can access a collection using c[name] or c.name, where c is a Collection, but what exactly does a sub-collection mean? I couldn't find any use of the term in the mongodb docs. What I'm assuming, is that it…
bigblind
  • 12,539
  • 14
  • 68
  • 123
2
votes
1 answer

using the sitemap package with django on heroku

Installing sitemap on heroku and getting it run is showing the following issue below. I'm following the advice of: https://docs.djangoproject.com/en/1.8/ref/contrib/sitemaps/ and putting sitemaps into my requirements.txt However when executing…
disruptive
  • 5,687
  • 15
  • 71
  • 135
2
votes
1 answer

How can I search in MongoDB ISODate field from Python?

I have an API from which I receive a query. This API is in Python. I call it from a django app (views.py). Then, I want to query my MongoDB collection, using mongoengine: api_response = requests.get("http://*******", {'query':query}) #We call the…
LM91
  • 53
  • 1
  • 7
2
votes
1 answer

including a NumberInt in a dict for pymongo

I need to load a list of dicts (see below) into a mongoDB. Within mongo, you have to define an int type as NumberInt(). Python doesn't recognize this as a valid type for a dict. I've found pages on custom encoding for pymongo that don't actually…
debara
  • 357
  • 1
  • 2
  • 9
2
votes
1 answer

How to know the creation date of a database in MongoDB

How to know the creation date of a database in MongoDB for database creation the keyword "use" and it also switches to the databases which is already present and show dbs list the databases . but for a particular database, how to know the creation…
2
votes
1 answer

pymongo, count query slower than mongo shell

everyone. I have a trouble at pymongo. pymongo 3.0.3 MongoDB 2.6.10 (on localhost) The following query run at the mongo shell, I got result in 3 seconds. $ mongo mydb > db.products.count({'categories': { '$elemMatch': {'code':…
Kohei Sugimura
  • 326
  • 1
  • 10
2
votes
1 answer

Aggregate averages from Embedded Documents

My document structure is shown here: { "_id" : ObjectId("52517d9e6e0af435ddd48219"), "date" : ISODate("2013-10-06T18:11:26.329Z"), "engines" : { "ahnlab" : { "definitions" : ISODate("2000-01-01T00:00:00.000Z"), …
Onca
  • 1,113
  • 3
  • 17
  • 31
2
votes
2 answers

Mongodb's geoNear In Flask and Mongoengine

I am using flask and mongoengine. How do I use mongodb's geoNear query? I am trying to use pymongo like this using this link: db.command(SON([('geoNear', 'content'), ('near', coordinate)])) If I am on the right way. How do I create pymongo's db…
min
  • 41
  • 1
  • 4