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

Update field with $currentDate on pymongo not working

I am looking to update the field "UpdatedDate" with the current date using $currentDate function but it's not working. The code below gives me the error: OperationFailure: Invalid modifier specified…
Shruti
  • 21
  • 3
2
votes
1 answer

Mongo Bounding Box Query with Limit

We are using mongo (via pymongo) to store a database of points in our system. This data is returned via our api using bounding box queries ($geoWithin). We want to limit the number of results returned to 200 sorted from the center. I'm trying to…
keithhackbarth
  • 9,317
  • 5
  • 28
  • 33
2
votes
0 answers

MongoDB Upsert : $set only on update and not on Insert

Hi I am really struggling to get an insert working with MongoDB. My schema basically will look like this. I will be recording pages hits every hour. I will be recording this for many different pages so efficiency is important. I have read that…
phunks
  • 29
  • 2
2
votes
1 answer

Unable to serialize JSON object from MongoDB in python

I have the following JSON stored in my MongoDB: { "_id" : ObjectId("54fed786265e7f01d66ca778"), "id" : "http://some.site.somewhere/entry-schema#", "schema" : "http://json-schema.org/draft-04/schema#", "description" : "schema for an fstab…
Anvith
  • 477
  • 9
  • 22
2
votes
2 answers

Performing sentiment analysis on a mongodb collection containing JSON elements (tweets) in Python

Hi I have created a python script using tweepy to stream tweets based on a keyword array into a mongodb collection based on the name of the element in the array that it was filtered by via pymongo ie (apple tweets saved to an apple collection). This…
philmckendry
  • 555
  • 6
  • 21
2
votes
1 answer

Writing Data Into CSV Format File

I'm trying to write some data into CSV format using fetched data from MongoDB, with Mongopy. Currently, the headers are currently set, and the problem is that the actual data is not being inserted into the CSV file. here is the code snippet : from…
Pouya Ataei
  • 1,959
  • 2
  • 19
  • 30
2
votes
1 answer

bson.json_util datetime encode and decode best practice

I'm trying to encode & decode python datetime object using pymongo's bson utils. What's best practice here? >>> from bson import json_util >>> import datetime >>> utcnow = datetime.datetime.utcnow() >>> x = json_util.dumps({'now': utcnow}) >>>…
estobbart
  • 1,137
  • 12
  • 28
2
votes
1 answer

mongodb date comparison between ISO string and datetime

I have a MongoDB collection where the date attribute is stored in the following format {'date': "2014-05-28T13:02:46"} I receive a query from the user in my Python server which is in the format '2014-05-28' that I have to compare against 'date'. I…
ubh
  • 607
  • 1
  • 10
  • 15
2
votes
1 answer

Get data of Referenced objects in MongoEngine query, not just id

I have a set of models as below: import mongoengine as mongo class Post(mongo.DynamicDocument): text = mongo.StringField() class User(mongo.DynamicDocument): name = mongo.StringField(required=True) posts =…
kelvintaywl
  • 215
  • 2
  • 9
2
votes
1 answer

How to get class of pymongo database suitable for isinstance()?

I have a test where I'm trying to identify if I've successfully gotten an instance of a database using pymongo, and would like to use isinstance(obj, class) in an assertion. However I cant figure out how to get a class (not instance) of the…
labroid
  • 452
  • 4
  • 14
2
votes
1 answer

MongoDB update an array element matching a condition using $push

I'm using Python and Mongo for the fist time together and in documentation I wasn't able to find what I need. So my data object looks like this { "_id" : ObjectId("54d372597d74523bc6991b9b"), "id_user" : "2000001", "date_registrated" : "2015-01-21…
T0plomj3r
  • 685
  • 1
  • 9
  • 23
2
votes
3 answers

MongoDB file path as unique index

How should I organize my collection for documents like this: { "path" : "\\192.168.77.1\user\1.wav", // unique text index "sex" : "male", "age" : 28 // some fields } I use this scheme in Python (pymongo): client = MongoClient(self.addr) db =…
Max Tkachenko
  • 792
  • 1
  • 12
  • 30
2
votes
2 answers

How to display ImageGridFSProxy in HTML?

I have several images stored within MongoDB and I would like to display them now in a web page. I'm using Flask for my application. The record has a binary field named "payload" class BinaryFile(mongo.Document): created_at =…
Brian Dolan
  • 3,086
  • 2
  • 24
  • 35
2
votes
2 answers

Slow MongoDB/pymongo query

I am submitting a pretty simple query to MongoDB (version 2.6) using the pymongo library for python: query = {"type": "prime"} logging.info("Querying the DB") docs = usaspending.get_records_from_db(query) logging.info("Done querying. Sorting the…
Arnob
  • 467
  • 1
  • 4
  • 13
2
votes
2 answers

How to populate wtform select field using mongokit/pymongo?

I'm trying to create a SelectField using a mongodb query, but so far I haven't been successful: # forms.py in blueprint CATEGORIES = [] for item in db.Terms.find(): CATEGORIES.append((item['slug'], item['name'])) class TermForm(Form): …
eneepo
  • 1,407
  • 3
  • 21
  • 32