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

广州市建设企业网站平台python18+21

广州市建设企业网站平台,python18+21,所有搜索引擎蜘蛛不来网站了,重庆网站建设快速建站目录 一、数据库操作 1、创建数据库 2、删除数据库 二、集合操作 1、创建集合 2、删除集合 三、文档操作 1、创建文档 2、 插入文档 3、查看文档 4、更新文档 1#xff09;update() 方法 2#xff09;replace() 方法 一、数据库操作 1、创建数据库 创建数据库…目录 一、数据库操作 1、创建数据库 2、删除数据库 二、集合操作 1、创建集合 2、删除集合 三、文档操作 1、创建文档 2、 插入文档 3、查看文档 4、更新文档 1update() 方法 2replace() 方法 一、数据库操作 1、创建数据库 创建数据库的语法格式如下 use DATABASE_NAME 如果数据库不存在则创建数据库否则切换到该数据库 show dbs;  admin  0.000GB config 0.000GB  local 0.000GB  mytest 0.000GB   use test01   switched to db test01   ​db   test01   ​show dbs;  admin  0.000GB config 0.000GB  local 0.000GB  mytest 0.000GB   数据库创建之后如果要显示出来需要插入数据如下 test01 db.test01.insert({name:zhangsan}); {acknowledged: true,insertedIds: { 0: ObjectId(64e0919af39cec8c5fc1dec8) } } test01 show dbs admin 40.00 KiB config 72.00 KiB local 72.00 KiB test01 40.00 KiB MongoDB 中默认的数据库为 test如果没有创建新的数据库集合将存放在 test 数据库中。 2、删除数据库 MongoDB 删除数据库的语法格式如下 db.dropDatabase()   删除当前数据库默认为 test你可以使用 db 命令查看当前数据库名。 dbtest01   db.dropDatabase()  { dropped :  test01, ok : 1 }   show dbs;  admin  0.000GBconfig 0.000GB  local 0.000GB  mytest 0.000GB   二、集合操作 1、创建集合 MongoDB 中使用 createCollection() 方法来创建集合。 语法格式 db.createCollection(name, options) 参数说明 name: 要创建的集合名称 options: 可选参数, 指定有关内存大小及索引的选项 选项可以是以下参数 在插入文档时MongoDB 首先检查固定集合的 size 字段然后检查 max 字段: #创建集合 test01 db.createCollection(test01) { ok : 1 } #查看集合 show tables; test01 show collections test01 db.getCollectionNames(); [ test01 ] 创建固定集合 mycol整个集合空间大小 6142800 KB, 文档最大个数为 10000 个。 test db.createCollection(mytest,{capped: true,autoIndexId:true,size:6142800,max:10000}) { ok: 1 }test db.createCollection(mytest01,{capped: true,size:6142800,max:10000}) { ok: 1 } test show tables; mytest mytest01 在  MongoDB 中不需要创建集合。当插入一些文档时MongoDB 会自动创建集合。 test01 db.mytest02.insert({name02:openlab}) {acknowledged: true,insertedIds: { 0: ObjectId(64e0939bf39cec8c5fc1dec9) } } test01 show tables; mytest02 test01 2、删除集合 MongoDB 中使用 drop() 方法来删除集合。 语法格式 db.collection.drop() 返回值 如果成功删除选定集合则 drop() 方法返回 true否则返回 false。 在数据库 mydb 中我们可以先通过 show collections 命令查看已存在的集合 db test show tables; mytest mytest01 mytest02 db.mytest.drop() true show tables; mytest01 mytest02 三、文档操作 文档的数据结构和 JSON 基本一样。 所有存储在集合中的数据都是 BSON 格式。 BSON 是一种类似 JSON 的二进制形式的存储格式是 Binary JSON 的简称。 MongoDB 使用 insert() 或 save() 方法向集合中插入文档语法如下 db.collection.insert(document)  db.collection.insertOne()  db.collection.insertMany()   insert(): 若插入的数据主键已经存在则会抛 org.springframework.dao.DuplicateKeyException 异常提示主键重复不保 存当前数据。 1、创建文档 db.collection.insertOne() 用于向集合插入一个新文档语法格式如下 db.collection.insertOne( document, { writeConcern: document } ) db.collection.insertMany() 用于向集合插入一个多个文档语法格式如下 db.collection.insertMany( [ document 1 , document 2, ... ], { writeConcern: document, ordered: boolean } ) 参数说明 document要写入的文档。 writeConcern写入策略默认为 1即要求确认写操作0 是不要求。 ordered指定是否按顺序写入默认 true按顺序写入。 在 test 数据库中创建集合 col包含如下文档如果没有该集合则创建: #创建集合并插入文档 test01 use test switched to db test test db.col.insert({title:MongoDB, ... description:MongoDB是一个nosql数据库, ... by:openlab, ... url:http://www.xiaooupeng.com, ... tags:[mongodb,database,nosql], ... likes:100 ... }) {acknowledged: true,insertedIds: { 0: ObjectId(64e0948ff39cec8c5fc1deca) } }#查看该集合 test db.col.find() [{_id: ObjectId(64e0948ff39cec8c5fc1deca),title: MongoDB,description: MongoDB是一个nosql数据库,by: openlab,url: http://www.xiaooupeng.com,tags: [ mongodb, database, nosql ],likes: 100} ] 先创建变量 test document({title:MongoDB, ... description:MongoDB是一个nosql数据库, ... by:openlab, ... url:http://www.xiaooupeng.com, ... tags: [ mongodb, database, nosql ], ... likes: 100 ... })执行后输出如下 {title: MongoDB,description: MongoDB是一个nosql数据库,by: openlab,url: http://www.xiaooupeng.com,tags: [ mongodb, database, nosql ],likes: 100 } 2、 插入文档 db.collection.insertOne()  # 插入一个文档 db.collection.insertMany() # 插入多个文档 db.collection.insert()       # 插入可以插入一个文档也可以插入多个文档 多一个判断的步骤 test db.co101.insert(document) {acknowledged: true,insertedIds: { 0: ObjectId(64e0957af39cec8c5fc1decb) } } 3、查看文档 1 test db.co101.find() [{_id: ObjectId(64e0957af39cec8c5fc1decb),title: MongoDB,description: MongoDB是一个nosql数据库,by: openlab,url: http://www.xiaooupeng.com,tags: [ mongodb, database, nosql ],likes: 100} ] 2 test var documentdb.collection.insertOne({test01:123}) test document {acknowledged: true,insertedId: ObjectId(64e095dbf39cec8c5fc1decc) } 3  test var test02 db.coll02.insertMany([{test02:02},{test0202:0202}])test test02 {acknowledged: true,insertedIds: {0: ObjectId(64e09679f39cec8c5fc1decd),1: ObjectId(64e09679f39cec8c5fc1dece)} } 查询 db.collection.find() 等值查询 {field: value} 操作符 {field: {$operater1: value1}.... } { status: { $in: [ A, D ] } } 比较 $eq Matches values that are equal to a specified value. $gt Matches values that are greater than a specified value. $gte Matches values that are greater than or equal to a specified value. $in Matches any of the values specified in an array. $lt Matches values that are less than a specified value. $lte Matches values that are less than or equal to a specified value. $ne Matches all values that are not equal to a specified value. $nin Matches none of the values specified in an array. 逻辑 $and { $and: [ { status: A }, { qty: { $lt: 30 } } ] } $or { $or: [ { status: A }, { qty: { $lt: 30 } } ] } $nor $not 元素 $exists $type # 正则表达式 $regex { field: { $regex: /pattern/, $options: options } } { field: { $regex: pattern, $options: options } } { field: { $regex: /pattern/options } } 4、更新文档 MongoDB 使用 update() 和 replace() 方法来更新集合中的文档。 1update() 方法 update() 方法用于更新已存在的文档。语法格式如下 db.collection.update(  query, update,  {  upsert: boolean,  multi: boolean,  writeConcern: document  }  )  db.inventory.updateOne({ item: paper }, # 查询条件{$set: { size.uom: cm, status: P }, # $set: 更新操作符# size.uom: cm , status: P$currentDate: { lastModified: true }} ) 参数说明 query : update 的查询条件类似 sql update 查询内 where 后面的。 update : update 的对象和一些更新的操作符如$,$inc...等也可以理解为 sql update 查询内 set 后面的 upsert : 可选这个参数的意思是如果不存在 update 的记录是否插入 objNew,true 为插入默认是 false不插入。 multi : 可选mongodb 默认是 false,只更新找到的第一条记录如果这个参数 为 true,就把按条件查出来多条记录全部更新。 writeConcern :可选抛出异常的级别。 #查看集合 test db.co101.find() [{_id: ObjectId(64e0957af39cec8c5fc1decb),title: MongoDB,description: MongoDB是一个nosql数据库,by: openlab,url: http://www.xiaooupeng.com,tags: [ mongodb, database, nosql ],likes: 100} ]#更新集合 test db.co101.update({title : MongoDB},{$set:{title : MongoDB_updat e}}) {acknowledged: true,insertedId: null,matchedCount: 1,modifiedCount: 1,upsertedCount: 0 }#查看更新后的集合 #1 test db.co101.find() [{_id: ObjectId(64e0957af39cec8c5fc1decb),title: MongoDB_updat e,description: MongoDB是一个nosql数据库,by: openlab,url: http://www.xiaooupeng.com,tags: [ mongodb, database, nosql ],likes: 100} ] #2 test db.co101.find().pretty() [{_id: ObjectId(64e0957af39cec8c5fc1decb),title: MongoDB_updat e,description: MongoDB是一个nosql数据库,by: openlab,url: http://www.xiaooupeng.com,tags: [ mongodb, database, nosql ],likes: 100} ]#以上语句只会修改第一条发现的文档如果你要修改多条相同的文档则需要设置 multi 参数为 true test db.co101.update({title : MongoDB},{$set:{title : MongoDB_updat e}},{multi:true}) {acknowledged: true,insertedId: null,matchedCount: 0,modifiedCount: 0,upsertedCount: 0 } 2replace() 方法 db.inventory.replaceOne({ item: paper },{ item: paper, instock: [ { warehouse: A, qty: 60 }, { warehouse: B, qty: 40 } ] } )test db.col01.insertOne( ... {name:zhangsan}, ... {age:22} ... ) {acknowledged: true,insertedId: ObjectId(64e0a0b7f39cec8c5fc1decf) }test db.col01.find() [ { _id: ObjectId(64e0a0b7f39cec8c5fc1decf), name: zhangsan } ] test db.col01.replaceOne({name:lisi},{age:23}) {acknowledged: true,insertedId: null,matchedCount: 0,modifiedCount: 0,upsertedCount: 0 }test db.col01.replaceOne({name:zhangsan},{name:lisi}) {acknowledged: true,insertedId: null,matchedCount: 1,modifiedCount: 1,upsertedCount: 0 } test db.col01.find() [ { _id: ObjectId(64e0a0b7f39cec8c5fc1decf), name: lisi } ] test
http://www.hkea.cn/news/14507971/

相关文章:

  • 网站做seo推广 s软件园专业做网站
  • 在哪个网站可以做酒店预定单sae storage wordpress
  • 做外贸常用那几个网站广告公司的经营模式
  • s上海网站建设个人养老金制度有望年内
  • 淮南餐饮网站建设餐饮类网站设计
  • 农产品网站如何做地推什么是网站域名
  • 常用网站后台地址网站怎么做关键词怎么优化
  • 网站开发技术入股协议网页设计速成培训
  • 建个官方网站要多少钱免费制作ppt软件
  • 高端网站建设大概多少费用取消wordpress 黑标题
  • 做良心网站企业查询系统官网天眼查
  • 做暧暧小视频有声音的网站网站建设好找工作
  • 怎么做影视网站小程序开发官网
  • 工商网站备案办法wordpress关键词内链
  • 类似猪八戒的网站建设怎么做淘宝联盟网站
  • ipad网站制作广州有哪些科技公司
  • 威海好的网站建设公司深圳seo外包
  • 网站建设维护属于什么专业磁县专业做网站
  • 韶关市住房和城乡建设局网站网站动态画面用啥做
  • wordpress调用图片路径排名优化培训
  • 制作公司网站需要几个数据表wordpress 自定义按钮
  • 建设网站简单教程电商公司怎么运营和管理
  • 沙河口网站建设办公室装修怎么做账
  • 网站制作怎么赚钱商务网站建设的一般流程图
  • 如何创办自己的网站wordpress在哪里登陆
  • 17做网站广州沙河网站哪些付款二维码是怎么做的
  • 宸建设计网站计算机专业都学什么
  • 网站建设质量如何衡量免费网站容量大
  • 母版做双语网站wordpress登录框插件
  • php自己做网站广州科技有限公司