hello world!!!!!

写下自己的一些心得,写下自己问题的方式,写下程序之路的艰辛,希望能够有朝一日成为大牛。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MongoDB Python create by lee

Posted on 2011-04-19 17:22  陈力  阅读(542)  评论(0编辑  收藏  举报
oot@ubuntu:/home/lee/mongodb-linux-i686-1.6.4/bin# python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from_pymongo_import Connection
  File "<stdin>", line 1
    from_pymongo_import Connection
                                 ^
SyntaxError: invalid syntax
>>> improt pymongo
  File "<stdin>", line 1
    improt pymongo
                 ^
SyntaxError: invalid syntax
>>> import pymongo
>>> from pymongo import Connection
>>> conection=Connection()
>>> connection=Connection('localhost',1234)
>>> db=connection['test']
>>> collection=db['test']
>>> import datetime
>>> post ={"author": "mike",                                                           

           "text" : "my first blo post!",                                               

           "tags" :["mongodb","python","pymongo"],                                  

           "date" :datetime.datetime.utcnow()}
>>> posts=db.posts
>>> posts.insert(post)
ObjectId('4dad537e1d41c80d2f000000')
>>> db.collection_names()
[u'posts', u'system.indexes']
>>> posts.find_one()
{u'date': datetime.datetime(2011, 4, 19, 9, 18, 34, 441000), u'text': u'my first blo post!', u'_id': ObjectId('4dad537e1d41c80d2f000000'), u'author': u'mike', u'tags': [u'mongodb', u'python', u'pymongo']}

 can kao lian jie

http://api.mongodb.org/python/1.10.1%2b/tutorial.html