from pymongo import MongoClient
# port: 27017
client = MongoClient(host='10.0.102.67')
print(client)
#
db = client.mydb
print(db)
course = db.course
r =course.insert({'cname':'python','grade':4})
print(r)
course_list = [{'cname':'mysql','grade':3},{'cname':'html','grade':3},{'cname':'javascript','grade':4}]
r = course.insert(course_list)
print(r)
r = course.update({'cname':'javascript'},{'$set':{'grade':4}})
print(r)
r= course.remove({'cname':'html'})
print(r)
r= course.find().sort([('grade',1),('cname',1)])
print(r)
for data in r:
print(data)
# select * from emp order by age,sal
# r = course.find({'grade':{'$in':(3,4,1)}}).sort([('grade',-1)])
r = course.find({'$or':[{'cname':'python'},{'grade':{'$lte':3}}]})
for data in r:
print(data)
mongo在pycham上使用
于 2019-09-03 08:53:39 首次发布