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))


​Mongodb query​