mongodb 数据库
时间:2021-07-01 10:21:17
帮助过:11人阅读
mongodb://admin:818919@127.0.0.1:27017/‘)
-
创建客户端链接对象
- client =
MongoClient()
-
print(client)
-
创建集合
- course=
db.course
from pymongo
import MongoClient
client = MongoClient(
‘mongodb://admin:818919@127.0.0.1:27017/‘)
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‘: 3
}})
print(r)
删除
r = course.remove({
‘cname‘:
‘html‘})
查询
r = course.find().sort([(
‘grade‘,1
)])
print(r)
for data
in r:
print(data)
Key Binding Resolver
Linter
Severity Provider Description Line
Git
GitHub
Create Repository
Initialize a new project directory with a Git repository
Create repository
mongodb 数据库
标签:分布式存储 date var ber span 中文 类型 选择 restore