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

php可以独立做网站吗四种营销模式

php可以独立做网站吗,四种营销模式,可以做哪些网站有哪些,做动画 的 网站目录 一、数据库操作 1、创建数据库 2、删除数据库 二、集合操作 1、创建集合 2、删除集合 三、文档操作 1、创建文档 2、 插入文档 3、查看文档 4、更新文档 1)update() 方法 2)replace() 方法 一、数据库操作 1、创建数据库 创建数据库…

目录

一、数据库操作

1、创建数据库

2、删除数据库

二、集合操作

1、创建集合

2、删除集合

三、文档操作

1、创建文档

2、 插入文档

3、查看文档

4、更新文档

1)update() 方法

2)replace() 方法


一、数据库操作

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: 可选参数, 指定有关内存大小及索引的选项

    选项可以是以下参数

image-20230201175055270

在插入文档时,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 document=db.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() 方法来更新集合中的文档。

1)update() 方法

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
}

2)replace() 方法

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.dinnco.com/news/37172.html

相关文章:

  • 长江日报武汉疫情邯郸seo优化公司
  • 苏州城乡住房建设厅网站win10优化大师怎么样
  • 二级网站免费建西安seo
  • 网站建设案例基本流程郑州网站seo推广
  • 厦门住房和城乡建设局网站数据统计网站
  • asp 网站开发 软件深圳搜索引擎
  • 新郑做网站市场营销推广方案怎么做
  • 网站和网页的不同海外游戏推广平台
  • 电子商务行业网站域名估价
  • 网站打开404错误怎么解决百度app关键词优化
  • 软件开发公司简介范文大全广州seo网络培训课程
  • 视频网站备案网站seo优化技巧
  • 太仓有专门做网站的地方吗宁波好的seo外包公司
  • 深圳建站公司的小技巧优化的含义是什么
  • 网站 模块制作小程序的软件
  • 重庆企业网站设计制作百度在全国有哪些代理商
  • 旅游网站技术流程图广州seo网站推广优化
  • 山西太原做网站惠州抖音seo策划
  • 郑州网站制作公司指数函数求导公式
  • 温州网站制作策划学技术的培训学校
  • 宣传 网站建设方案长春seo招聘
  • 动漫制作专业名称做优化关键词
  • wordpress get_usermeta成都网站改版优化
  • wordpress开发网站模板推广方式和推广渠道
  • 中心城网站建设如何做友情链接
  • 好看的网站都找谁做的南宁seo网络推广
  • 郑州市做网站的谷歌浏览器下载视频
  • 聊城网站建设报价免费seo在线工具
  • 外贸综合服务网站建设谷歌浏览器安卓版
  • 建设公司网站 优帮云站长之家字体