Examples of comparison operators for mongodb in Python using pymongo

MongoDB gives 7 different comparison operators. here is a list of all 7 and how to use them in pymongo.

client = MongoClient("localhost", 27041)
db = client['test_database']
col = db["test_col"]

col is the collection object on which the find queries will be done

  • $gt - greater than operator
  • Matches values that are greater than the value specified in the query.

    col.find({ 'price' : { '$gt' : 25 }})

How to convert a property in MongoDB from text to date type using pymongo

I was using mongodb as my preferred database for a pet project. I found out very recently that while storing data, a property which should have been stored as ISOdate format was being stored as a string. here is a code to fix that in python using pymongo

from pymongo import MongoClient
from datetime import datetime
def fixTime(host, port, database, collection, attr, date_format):
Read more about How to convert a property in MongoDB from text to date type using pymongo

How to fix zsh:corrupt history file

After i forcefully restarted my Ubuntu 13.04 laptop and fired up zsh, i was greeted with this message.


zsh: corrupt history file /home/salil/.zsh_history

a quick googling didn't offer much insight. So i decided to take matters into my hand. I created a backup and opened the file in vi Read more about How to fix zsh:corrupt history file

Scraping IMDB website for US specific content

IMDB page renders differently for different locations. Lot of information on the website also changes heavily with respect to the country the user lives. So what can we do to scrape a US specific webpage from India?. Read more about Scraping IMDB website for US specific content

Python Virtual Environment and Cron Jobs

Virtual Environments or virtualenv is the best way to develop multiple python projects in a machine. It helps to track, update and install only those modules which the project is dependent on. I use virtualenv a lot and recently faced trouble while trying to run a cron job with a virtualenv. Read more about Python Virtual Environment and Cron Jobs

How to install zeromq and its python bindings in Ubuntu 13.04

the command to install zeromq is

sudo apt-get install libzmq1

To install the python bindings use

pip install pyzmq
Read more about How to install zeromq and its python bindings in Ubuntu 13.04

Three lessons : create git submodules, create and name python packages

I wanted to use an existing github repository inside inside a pet project of mine. the best way to do so is to use git submodule add command

git submodule add repository_url directory_name

this command clones the repository to the desired directory name. directory name is an optional field here. Read more about Three lessons : create git submodules, create and name python packages

Best Talks of Pycon India 2013, Bangalore

I personally found the following talks of Pycon 2013 inspiring and informative

Beautiful Soup : errors while parsing large documents

A few days back, i was trying to scrape amazon's website for a hobby side project and got into trouble while parsing the document. I was using Beautiful Soup for parsing the downloaded amazon webpage and mysteriously, it was only parsing the first 500 to 600 lines compared to the entire 10000 line document. Read more about Beautiful Soup : errors while parsing large documents

What i learned from PyCon India 2013, Bangalore

My first ever pycon was this year from August 31 to September 1st. I wanted to get inspired and awed by it, in a way i was expecting a little too much from it

I did not attend any workshops and cannot really comment on their quality. I did attend some talks and i can confidently say that the quality was just average. most talks were aimed at recruiting participants for the company the speaker was representing and some speakers looked like they were being forced to speak since their company has paid a hefty sponsorship fee. Read more about What i learned from PyCon India 2013, Bangalore

Pages

About the author

Subscribe to Salil Panikkaveettil RSS