码迷,mamicode.com
首页 > 数据库 > 详细

python操作mongodb

时间:2019-06-29 15:00:14      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:for   finish   end   exe   python   name   script   ted   操作   

import pymongo
client=pymongo.MongoClient("192.168.14.179",27017)
db=client[‘test‘]
stu=db[‘stu‘]
s1={‘name‘:‘lz‘,‘age‘:27}
s1_id=stu.insert_one(s1).inserted_id
s2=stu.find_one()
for i in stu.find():
print(i)
#方法2
x=stu.find()
x.next()
x.next()
x.next()
x.next()


print(stu.count())

#结果
E:\py1902project\venv\Scripts\python.exe E:/py1902project/xxx/xxx.py
{‘_id‘: ObjectId(‘5ca34a005daca34f28389b11‘), ‘name‘: ‘wang‘, ‘gender‘: 1.0}
{‘_id‘: ObjectId(‘5ca34a0a5daca34f28389b12‘), ‘name‘: ‘chen‘, ‘gender‘: 1.0}
{‘_id‘: ObjectId(‘5ca34a0e5daca34f28389b13‘), ‘name‘: ‘chen‘, ‘gender‘: 1.0}
{‘_id‘: ObjectId(‘5ca34a7a5daca34f28389b14‘), ‘name‘: ‘da‘}
{‘_id‘: ‘1002‘, ‘name‘: ‘wbk‘}
{‘_id‘: ObjectId(‘5ca35d16428ed81704b9f6b6‘), ‘name‘: ‘lz‘, ‘age‘: 27}
6

Process finished with exit code 0

python操作mongodb

标签:for   finish   end   exe   python   name   script   ted   操作   

原文地址:https://www.cnblogs.com/ldsice/p/11106429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!