qaqa12345667 发表于 2015-4-26 07:37:25

mongoDB python应用

  1:下载pymongo-1.5.2-py2.6-win32.egg (md5)
  2:下载 setuptools-0.6c11.win32-py2.6.exe,解压安装,他会主动安装Python26\Lib\site-packages,
  3:安装egg,cmd 命令:C:\Python26>C:\Python26\Lib\site-packages\easy_install pymongo-1.5.2-py2.6-win3
  2.egg,C:\Python26\Lib\site-packages\easy_install为你安装setuptools-0.6c11.win32-py2.6.exe地址,后面是你的 pymongo-1.5.2-py2.6-win32.egg地址
  


代码



C:\Python26>C:\Python26\Lib\site-packages\easy_install.py pymongo-1.5.2-py2.6-wi
n32.egg
Processing pymongo-1.5.2-py2.6-win32.egg
Copying pymongo-1.5.2-py2.6-win32.egg to c:\python26\lib\site-packages
Adding pymongo 1.5.2 to easy-install.pth file
Installed c:\python26\lib\site-packages\pymongo-1.5.2-py2.6-win32.egg
Processing dependencies for pymongo==1.5.2
Finished processing dependencies for pymongo==1.5.2
  
  OK,安装完成。
  下面是测试阶段:
  


C:\Python26>C:\Python26\Lib\site-packages\eeasy_install pymongo-1.5.2-py2.6-win3

2.eggC:\Python26>C:\Python26\Lib\site-packages\eeasy_install pymongo-1.5.2-py2.6-win32.egg  




#coding=utf-8
from pymongo import Connection
conn = Connection("localhost")
db = conn.foo
test = {"id":1, "novle":"测试一下"}
db.foo.save(test)
cursor = db.foo.find()
for i in cursor:
    print i
  
  out
  




{u'_id': ObjectId('4bc193c11724bc0cc4000000'), u'id': 1, u'novle': u'\ufffd\ufffd\ufffd\ufffd'}

  
  OK 测试成功
  
  下次就是讲 怎么在DJANGO里面 使用mongodb了
  
页: [1]
查看完整版本: mongoDB python应用