Skip to main content

MongoDB example using pymongo on Linux


1. Install Mongodb
     #yum install mongodb
     #yum install mongodb-server

2. Install pymongo

3. Sample Script





from pymongo import Connection
import datetime
import time
import os, sys
reload(sys)
sys.setdefaultencoding("latin1")

connection = Connection("localhost", 27017)

db = connection.sample_db


#Insert a record on a table (sample_tb)

post = {"author": "Mike","text": "My first blog post!","tags": ["mongodb", "python", "pymongo"],"date": datetime.datetime.utcnow()}

posts = db.sample_tb

posts.insert(post)



#Select a record on a table (sample_tb)

posts = db.sample_tb

posts.find_one()

posts.find_one({"author": "Mike"})


for post in posts.find():
 print post['author']



#Delete a record on a table (sample_tb)

posts = db.sample_tb

posts.remove({"author": "Mike"})

Comments

Popular posts from this blog

Automated Testing with Behat & Mink on Linux

Have time to read my introduction. Behat + Mink + Selenium Server will do the automatic testing for your website. Behat handles your test cases in a form of a sentence which consist of the following Feature - which is a description of your test case. Example is "Title Checking" Scenario - Feature consist of Scenario's Conditions - Scenario's consist of condition using the following tags "Given", "When", "Then", "And", "But" Example feature:  Feature: Google Search @javascript Scenario: Check Google Site When I go to " http://www.google.com " Then Capture a ScreenShot @javascript Scenario: Search Efren on Google Given I am on " http://www.google.com " When I input "Efren" in " gbqfq" element When press " Google Search " Then print current URL Then Capture a ScreenShot You need t...

Skipfish for CENTOS

#yum install openssl-devel #yum install pcre-devel #yum install libidn-devel #wget https://skipfish.googlecode.com/files/skipfish-2.10b.tgz #tar xzvf skipfish-2.10b.tgz #cd skipfish-2.10b #make #touch dict.wl #./skipfish -o output_dir -W dict.wl http://192.168.1.254

Initial Installation of RoR Centos, Fedora, Redhat

# yum install ruby # y um install gcc g++ make automake autoconf curl-devel openssl-devel zlib-devel httpd-devel apr-devel apr-util-devel sqlite-devel # yum install ruby-rdoc ruby-devel # y um install rubygems # mkdir ~/src # cd ~/src # wget http://production.cf.rubygems.org/rubygems/rubygems-2.2.2.tgz # cd rubygems-1.3.6 # ruby setup.rb Install Rails # gem update # gem update --system # gem install rails # gem install rails -V -----DONE