β

mac mongodb pymongo 简单使用

Waiting For You 35 阅读

1.安装mongodb

brew install mongodb
brew services start mongodb
brew services stop mongodb
brew services restart mongodb

写配置文件mongodb.conf

port=27017
dbpath=/Users/walle/Documents/mongoConfig/db
logpath=/Users/walle/Documents/mongoConfig/log.txt
#fork = true
mongod -f ./mongodb.conf

2.pymongo简单使用

2.1 find

mongoClient = pymongo.MongoClient('localhost')
db = mongoClient['article']
results = db['article_ori'].find({'is_t_b': 1, 'is_t_t':1, 'is_done':0}).limit(11)
#还可以转换成list,用skip和limit进行分页
resultsList = list(db['article_ori'].find({'is_t_t':0}).skip(10).limit(10))
for item in results:
  print(item)

2.2 更新

item['is_t_t'] = 1
db['article_ori'].update({'_id': id}, item)

2.3 插入

db['article_ori'].insert_one(dict(item))

http://www.waitingfy.com/archives/3353

作者:Waiting For You
记录一些关于android,cocos2d-x,objective-c,mfc,directX,c++,数学的东西
原文地址:mac mongodb pymongo 简单使用, 感谢原作者分享。

发表评论