Thursday, November 10, 2011

Hello Mongo + Python

Sample to use Python + mongo
1. install the pre-requisites (on macs/linux)
$easy_install pymongo

2. start python
$python
>>> import pymongo
>>> connection = pymongo.Connection("localhost")
>>> db=connection.test
>>> print db.mycoll.count()

and you are free to write python code using mongoDB.

Monday, October 31, 2011

Generate data in mongo

I love mongodb!


This is the "hello world"" / simplest way I have found to generate sample data in mongod.

1. ensure "mongod" is running
2. open mongo shell (run "mongo")
3. for (i=0; i< 1000;i++){ db.mycoll.insert({"val":i}); }

And what you have is a collection with 1000 docs.

Friday, May 20, 2011

python awesomesness 1

I am sure many folks go through this phase when writing python code after other languages.

return dict( zip(x, range(len(x))))

is a line of code I needed.

Converted a sorted list to a dictionary of list items and the index of the item.

Thursday, January 20, 2011

aws

If
ec2_describe_* returns nothing/blank, then the default region pointed to might be incorrect.
In my case,
ec2_describe_instances
ec2_describe_snapshots
etc, all returned blank
Setting
EC2_URL=https://us-west-1.ec2.amazonaws.com
in your shell fixes it.