python 连接 mongodb

来源:互联网 发布:产品经理设计软件 编辑:程序博客网 时间:2024/05/17 07:23

我的运行环境是Centos 6.3。首先是要安装pymongodb的库。用easy_install 安装。

#!/usr/bin/pythonfrom pymongo import Connectionimport timedb = Connection().jjystart = time.time()for i in xrange(1000000):        db.jjy.insert({"foo":"bar","baz":i,"z":10-i})#db.drop_collection("jjy");total = time.time() - start;print "%d s" % total

不知道是不是py的效率问题,花费了不到4分钟。

下面是mysql的,我写了一个存储过程

create procedure inser()begin declare a int default 1;  while a<1000001 do  insert into person(id) values(a);set a = a +1; end while;end;~           
用了1 分47 秒。

刚刚接触 mongodb。还没有一个清醒的认识,不喜勿喷

原创粉丝点击