MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap

Upload page content

You can upload content for the page named below. If you change the page name, you can also upload content for another page. If the page name is empty, we derive the page name from the file name.

File to load page content from
Page name
Comment

Revision 6 as of 2013-12-23 15:12:27
  • Python
  • pymongo

pymongo

PyMongo is a Python distribution containing tools for working with MongoDB, and is the recommended way to work with MongoDB from Python

http://api.mongodb.org/python/current/

Install from source on Slackware

  • cd /tmp
  • git clone git://github.com/mongodb/mongo-python-driver.git pymongo
  • cd pymongo/
  • su
  • python setup.py install

Eclipse - pydev

  • Window
  • Preferences
  • pydev
  • interpreter - python
  • Forced builtins
  • new
  • pymongo
  • apply Ok

Queries

Query by _id

   1 from bson import ObjectId
   2 import pymongo
   3 import datetime
   4 
   5 mongo = pymongo.Connection('192.168.1.1', 27017)
   6 dbx = mongo['dbx']
   7 collx = dbx['collx']
   8 
   9 nowx = datetime.datetime.now();
  10 currDay = datetime.datetime(nowx.year,nowx.month,nowx.day,0,0,0,0)
  11 
  12 query={'_id':ObjectId(objx.getId()) }
  13 print query
  14 res = collx.find_one(query )            
  15 print res

Driver windows Python 2.5

https://pypi.python.org/packages/2.5/p/pymongo/pymongo-2.6.3.win32-py2.5.exe

datetime.datetime is not JSON serializable

   1 from bson import json_util
   2 import json
   3 
   4 json.dumps(anObject, default=json_util.default)
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01