发表于: 2018-01-10 00:38:36

2 823


今天完成的事:

学习了mongodb以及pymongo 的基本用法

下载的zip版mongodb ,解压到适当路径下,将bin目录所在的路径添加到系统环境变量path下。选择一个目录下新建data文件夹,logs文件夹,logs文件夹下新建mongodb.log文件

 cmd输入mongod  --dbpath="D:/mongodb/data"  --logpath="D:/mongodb/logs/mongodb.log"

即可启动mongodb数据库

打开浏览器输入localhost:27012会有正确的响应

 cmd输入mongo可以配置或者修改数据库


 pymongo 

连接数据库

 from pymongo import MongoClient

 conn=MongoClient('127.0.0.1',27012)

 db=conn.test

 collection=db.students

 以上数据库或者集合如果没有,会自动创建

 集合中插曲数据

 result =collection.insert(something)

 result =collection.insert_one(something)

 result =collection.insert_many(somthing)

均可,用法稍不同

集合中更新数据

 result =collection.update(old,new)

 result =collection.update_one(old,new)

 result =collection.update_many(old,new)

查询数据

 result=collection.find(something)

 result=collection.find_one(something)

 result=collection.find_many(something)

删除数据

 result=collection.remove(something)

 result=collection.remove_one(something)

 result=collection.remove_many(something)




返回列表 返回列表
评论

    分享到