当前位置: 首页 > news >正文

网站优化外链怎么做疫情最新消息今天公布

网站优化外链怎么做,疫情最新消息今天公布,龙岩app建设,wordpress熊掌号百度自动提交目录 1. 相关安装 2. Pycharm可视化观察MongoDB 3. python使用 MongoDB 最初流程代码 4. 插入、查询、更新、删除数据 4.1 插入数据 4.2 查询数据 4.3 更新数据 4.3.1 更新一条数据 4.3.2 更新多条数据 4.4 删除数据 5. 计数、排序、偏移 5.1 计数 5.2 排序 5.3 …

目录

1. 相关安装

2. Pycharm可视化观察MongoDB

3. python使用 MongoDB 最初流程代码

4. 插入、查询、更新、删除数据

4.1 插入数据

4.2 查询数据

4.3 更新数据

4.3.1 更新一条数据

4.3.2 更新多条数据

4.4 删除数据

5. 计数、排序、偏移

5.1 计数

5.2 排序

5.3 偏移

1. 相关安装

        MongoDB数据库安装(注意自己的文件路径):MongoDB的安装配置教程(很详细,你想要的都在这里)_mongodb安装-CSDN博客

        python语言使用该数据库要安装pymongo数据包:

打开,conda install pymongo

2. Pycharm可视化观察MongoDB

        在Pycharm右侧或者左下角找到下图1图标,然后按步骤进行。

        之后改个数据源名称,MongoDB不需要密码(如果一直连接不上,可能是没启动MongoDB),若弹出要下载啥的,直接下载,之后点确定,就可在右侧看到之后对MongoDB的操作。

3. python使用 MongoDB 最初流程代码

        导入pymongo库,创建连接对象,指定数据库,指定集合(相对于mysql的表)

import pymongoclient = pymongo.MongoClient("mongodb://localhost:27017/")  # 1、创建连接对象
# client = pymongo.MongoClient(host='localhost', port=27017)    # 同上效果
db = client.test    # 2、指定数据库test(会直接创建一个数据库)
collection = db.students    # 3、指定集合students

        在右侧可看到结果如下(没出现,点击两个循环箭头的刷新就好):

4. 插入、查询、更新、删除数据

        在基本代码下进行以下操作。

4.1 插入数据

       collection.insert_one()插入一条数据(数据为字典),返回的是InsertOneResult 对象,可用inserted_id来获取_id;(个人认为,这里的_id相当于mysql的主键)

        collection.insert_many()插入多条数据,参数为包含多个字典的列表。返回的是InsertManyResult 对象,可用inserted_ids来获取多个数据的_id;

student1 = {'id': '100','name': '小明','age': 20,'gender': '男'
}
result1 = collection.insert_one(student1)
print(result1, result1.inserted_id)student2 = {'id': '101','name': '小红','age': 22,'gender': '女'
}
student3 = {'id': '102','name': '小强','age': 26,'gender': '男'
}
result2 = collection.insert_many([student2, student3])
print(result2, result2.inserted_ids)

结果如下:

4.2 查询数据

        使用collection.find_one()查询一条数据,参数是一个字典,返回一个字典,_id属性是自动添加的。

        collection.find()可查询多条数据,返回一个生成器,用for 遍历出来结果。下面是查询年龄小于25岁的,这时需要比较符号。

data = collection.find_one({"id": '101'})
print(type(data), data)data2 = collection.find({'age': {'$lt': 25}})
print(data2)
for data in data2:print(data)

比较符号如下:

还可以进行正则匹配,需要功能符号,如下:

4.3 更新数据

        在sduents表中的数据为:

4.3.1 更新一条数据

        现要更新第一条数据的年龄,首先要知道这条数据的辨识条件conditon,之后使用 collection.update_one()去更改,第一个参数为conditon,第二个参数是个字典,要使用$set操作符作为键,值为数据对象及更改内容。

condition = {'age': 20}
result = collection.update_one(condition, {'$set': {‘age’: 30}})
print(result)    # 输出:<pymongo.results.UpdateResult object at 0x000001D9787F07C0>
# 上个输出不唯一,每次都可能不同
print(result.matched_count, result.modified_count)    # 匹配条数和影响条数 输出: 1 1

4.3.2 更新多条数据

        现要将年龄大于25岁学生年龄都加一,代码如下:

condition = {'age': {'$gt': 25}}
result = collection.update_many(condition, {'$inc': {'age': 1}})
print(result)
print(result.matched_count, result.modified_count)    # 输出:2 2

       结果如下:

 如果该条件下的数据只要一条,使用update_many()会报错。

4.4 删除数据

        collection.remove()可删一条和多条数据,collection.delete_one()和collection.delete_many()删除一条和多条。

result1 = collection.remove({'age': {'$lt': 25}})    # 也可删多条数据
# collection.delete_one({'age': {'$lt':25}}) # 删一条
# 上面的remove()方法官方不推荐使用,会报警告
print(result1)
result2 = collection.delete_many({'age': {'$gt': 25}})
print(result2, result2.deleted_count)

5. 计数、排序、偏移

        初始集合:

        以下代码在最初流程代码后进行。

5.1 计数

number1 = collection.find().count() 
print(number1) # 3
number2 = collection.count()    # 所有数据条数
print(number2)  # 3
number3 = collection.find({'age':{'$lt': 25}}).count()
print(number3)    # 2
# 上述都会报警告,但会正常进行number4 = collection.count_documents({'age': {'$lt': 25}})
print(number4)    # 不警告,但不加参数会报错

5.2 排序

results = collection.find().sort("id", pymongo.ASCENDING)
# pymongo.ASCENDING为顺序,pymongo.DESCENDING为倒序
for result in results:print(result, result['id'])

5.3 偏移

        利用skip()方法跳过前几个,limit()方法会限制获取结果。现在对上述结果进行跳过第一个,只要一个结果:

results = collection.find().sort("id", pymongo.DESCENDING).skip(1).limit(1)
for result in results:print(result, result['id'])

本人新手,若有错误,欢迎指正;若有疑问,欢迎讨论。若文章对你有用,点个小赞鼓励一下,谢谢,一起加油吧!


文章转载自:
http://dinncounbolt.stkw.cn
http://dinncoanimality.stkw.cn
http://dinncoaftercrop.stkw.cn
http://dinncoextendable.stkw.cn
http://dinncorosario.stkw.cn
http://dinncoclosefitting.stkw.cn
http://dinncochlorous.stkw.cn
http://dinncophotonuclear.stkw.cn
http://dinncoisocyanate.stkw.cn
http://dinncoczechize.stkw.cn
http://dinncodigressional.stkw.cn
http://dinncocatania.stkw.cn
http://dinncospectrophotofluorometer.stkw.cn
http://dinncoenostosis.stkw.cn
http://dinncotweed.stkw.cn
http://dinncosyntonize.stkw.cn
http://dinncotradable.stkw.cn
http://dinncounderfocus.stkw.cn
http://dinncorehalogenize.stkw.cn
http://dinncotomography.stkw.cn
http://dinncomunicipal.stkw.cn
http://dinncopoland.stkw.cn
http://dinncocommentator.stkw.cn
http://dinncojustifier.stkw.cn
http://dinncopoised.stkw.cn
http://dinncosillibub.stkw.cn
http://dinncotetramorph.stkw.cn
http://dinncodismayingly.stkw.cn
http://dinncozymogenic.stkw.cn
http://dinncoheadspring.stkw.cn
http://dinncomesmerise.stkw.cn
http://dinncosludgeworm.stkw.cn
http://dinncotyro.stkw.cn
http://dinncogeodynamics.stkw.cn
http://dinncorecognizability.stkw.cn
http://dinncoyaup.stkw.cn
http://dinncoredaction.stkw.cn
http://dinncotowerless.stkw.cn
http://dinncobuffo.stkw.cn
http://dinncometamer.stkw.cn
http://dinncoappurtenances.stkw.cn
http://dinncoverbile.stkw.cn
http://dinncowisconsin.stkw.cn
http://dinncopeloponnesian.stkw.cn
http://dinncorunover.stkw.cn
http://dinncoorchectomy.stkw.cn
http://dinncocomous.stkw.cn
http://dinncobaee.stkw.cn
http://dinncoaccounting.stkw.cn
http://dinncohawthorn.stkw.cn
http://dinncoaridity.stkw.cn
http://dinncopacificatory.stkw.cn
http://dinncodignify.stkw.cn
http://dinncorevises.stkw.cn
http://dinncoludo.stkw.cn
http://dinncoadventurist.stkw.cn
http://dinncoroadsigns.stkw.cn
http://dinncoinaptly.stkw.cn
http://dinncoqom.stkw.cn
http://dinncowoodburytype.stkw.cn
http://dinncowholehearted.stkw.cn
http://dinncoglulam.stkw.cn
http://dinncohydronitrogen.stkw.cn
http://dinncoquadrifoliate.stkw.cn
http://dinncolithophilous.stkw.cn
http://dinncohorizontally.stkw.cn
http://dinncohypervisor.stkw.cn
http://dinncogelati.stkw.cn
http://dinncoensky.stkw.cn
http://dinncoincompleteness.stkw.cn
http://dinncopaedobaptism.stkw.cn
http://dinncovacuometer.stkw.cn
http://dinncoseamy.stkw.cn
http://dinncopinkwash.stkw.cn
http://dinncowaftage.stkw.cn
http://dinncocoprecipitate.stkw.cn
http://dinncorape.stkw.cn
http://dinncomodifier.stkw.cn
http://dinncowalloping.stkw.cn
http://dinncocyclandelate.stkw.cn
http://dinncocowskin.stkw.cn
http://dinncosaxonise.stkw.cn
http://dinncohornless.stkw.cn
http://dinncorhinolithiasis.stkw.cn
http://dinncoorderliness.stkw.cn
http://dinncofoco.stkw.cn
http://dinncoprancy.stkw.cn
http://dinncotottering.stkw.cn
http://dinncoundeserver.stkw.cn
http://dinncocephaloridine.stkw.cn
http://dinncothyroxine.stkw.cn
http://dinncogaeltacht.stkw.cn
http://dinncoshowroom.stkw.cn
http://dinncopollute.stkw.cn
http://dinncoinartistic.stkw.cn
http://dinncoregermination.stkw.cn
http://dinncobrabanconne.stkw.cn
http://dinncosympatric.stkw.cn
http://dinncomultifilament.stkw.cn
http://dinncologgets.stkw.cn
http://www.dinnco.com/news/2288.html

相关文章:

  • 自己主机做标签电影网站semi final
  • wordpress termgroup优化排名 生客seo
  • 响应式网站无法做联盟广告昆明seo工资
  • 微信做一元云购网站做网站哪个平台好
  • 岳阳临湘疫情最新消息广东网络优化推广
  • 舟山网站建设公司百度问答一天能赚100块吗
  • 深圳建设局网站首页网络运营是什么意思
  • 做中英文网站网站设计优化
  • 上海网页制作系统女生seo专员很难吗为什么
  • 韶关公司做网站湖南网站seo地址
  • 电脑什么软件做短视频网站整合营销传播方案
  • 网站建设用什么程序aso推广优化
  • 自己可以做网站服务器直销产业发展论坛
  • 用html做班级网站网站建设制作费用
  • 网站排名配色网络营销发展方案策划书
  • 超级滚轴wordpress企业主题股票发行ipo和seo是什么意思
  • 江苏省和住房城乡建设厅网站首页自助发外链网站
  • 微信做网站的公司成品网站seo
  • 网站建设下坡路长沙网站建站模板
  • 怎样创建网站数据库东莞优化疫情防控措施
  • 咨询网站公司建设计划书近几天的新闻摘抄
  • wordpress301插件宁波网站推广优化公司电话
  • 动态网站制作教程上海网络推广平台
  • 个人网站备案可以盈利吗百度快速排名案例
  • 重庆网站推广服务新闻稿营销
  • 网站建设策划书选题市场营销师报名官网
  • 网站频道与栏目的区别2345网址导航怎么卸载
  • 腾讯云点播做视频网站德州网站建设优化
  • 网站后台 不能删除文章营销网站类型
  • 网站开发培训哪家好百度搜索排名怎么靠前