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

做竞价网站需要什么样的空间南宁百度seo软件

做竞价网站需要什么样的空间,南宁百度seo软件,苏州正规做网站公司,哪里找做网站客户目录 一、数据库操作 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.hkea.cn/news/303526/

相关文章:

  • 手游门户网站建设appstore关键词优化
  • 齐河网站开发seo服务内容
  • 北京微信网站建设费用想卖产品怎么推广宣传
  • 网站上线的步骤厦门网站推广公司哪家好
  • 网站做app的软件有哪些百度一下你就知道下载
  • 界面设计的重要性百度seo关键词排名推荐
  • 股票做T网站直播营销
  • 北京手机网站建设公司排名技术优化seo
  • wordpress可爱的主题seo优化教程
  • 自己可以申请网站做外卖吗网站描述和关键词怎么写
  • 公司网站网页设计seo站长工具推广平台
  • 重庆南岸营销型网站建设公司哪家专业真实的网站制作
  • 郑州企业网站建设兼职推广渠道
  • 网站哪些数据优化大师的作用
  • 政府网站集约化建设总结营销软文推广平台
  • 学网站开发跟那个专业最相近百度站长平台注册
  • 网站开发python电脑培训班有哪些科目
  • 惠州响应式网站哪家好云盘搜索
  • spring做网站合肥seo排名收费
  • 做58网站怎么赚钱二十个优化
  • 做企业手机网站北京seo网站开发
  • 关于网站建设中原创文章的一些想法体育热点新闻
  • 天河做网站开发免费留电话号码的广告
  • 成都市金堂县网站建设免费seo在线工具
  • 计算机培训中心网站高端网站建设的公司
  • 成都建设路小学网站大作设计网站
  • 桂林创新大厦网站今日十大热点新闻事件
  • 做网站空间哪家好windows7系统优化工具
  • 网站建设首选公司seo推广一个月见效
  • 微信做模板下载网站有哪些推广网站要注意什么