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

开发网站建设方案凤山网站seo

开发网站建设方案,凤山网站seo,网站建设发生的成本如何记账,公司做网站都需要什么流程一、简介 1.1 Mongodb 是什么 MongoDB 是一个基于分布式文件存储的数据库,官方地址 MongoDB: The Developer Data Platform | MongoDB 1.2 为什么选择 Mongodb 操作语法与 JavaScript 类似,容易上手,学习成本低 二、核心概念 Mongodb 中…

一、简介

1.1 Mongodb 是什么

MongoDB 是一个基于分布式文件存储的数据库,官方地址 MongoDB: The Developer Data Platform | MongoDB

1.2 为什么选择 Mongodb

操作语法与 JavaScript 类似,容易上手,学习成本低

二、核心概念

Mongodb 中有三个重要概念需要掌握
数据库(database) 数据库是一个数据仓库,数据库服务下可以创建很多数据库,数据库中可以存
放很多集合
集合(collection) 集合类似于 JS 中的数组,在集合中可以存放很多文档
文档(document) 文档是数据库中的最小单位,类似于 JS 中的对象


JSON 文件示例:

{"accounts": [{"id": "3-YLju5f3","title": "买电脑","time": "2023-02-08","type": "-1","account": "5500","remarks": "为了上网课"},{"id": "3-YLju5f4","title": "请女朋友吃饭","time": "2023-02-08","type": "-1","account": "214","remarks": "情人节聚餐"},{"id": "mRQiD4s3K","title": "发工资","time": "2023-02-19","type": "1","account": "4396","remarks": "终于发工资啦!~~"}],"users":[{"id": 1,"name": "zhangsan","age": 18},{"id": 2,"name": "lisi","age": 20},{"id": 3,"name": "wangwu","age": 22}]
}

大家可以通过 JSON 文件来理解 Mongodb 中的概念

  • 一个 JSON 文件 好比是一个 数据库 ,一个 Mongodb 服务下可以有 N 个数据库
  • JSON 文件中的 一级属性的数组值 好比是 集合
  • 数组中的对象好比是 文档
  • 对象中的属性有时也称之为 字段

一般情况下

一个项目使用一个数据库

一个集合会存储同一种类型的数据

三、下载安装与启动

下载地址: Download MongoDB Community Server | MongoDB

建议选择 zip 类型, 通用性更强

配置步骤如下:

往下滑

选择安装包(建议不要选择最新的)

MongoDB6没有mongon需要自己去下载

MongoDB5有mongon

选择平台和类型进行下载

1> 将压缩包移动到 C:\Program Files 下,然后解压

2> 创建 C:\data\db 目录,mongodb 会将数据默认保存在这个文件夹(数据放这里

3> 以 mongodb 中 bin 目录作为工作目录,启动命令行

4> 运行命令 mongod

看到最后的 waiting for connections 则表明服务 已经启动成功

然后可以使用mongosh命令连接本机的 mongodb 服务

MongoDB6后无 “mongo.exe”

MongDB6.0后已经不再默认为你安装shell工具
在MongoDB\bin\ 下没有mongo.exe

解决

注意:

为了方便后续方便使用 mongod 命令,可以将 bin 目录配置到环境变量 Path 中

千万不要选中服务端窗口的内容 ,选中会停止服务,可以 敲回车 取消选中

四、命令行交互

命令行交互一般是学习数据库的第一步,不过这些命令在后续用的比较少,所以大家了解即可

4.1 数据库命令

  1. 显示所有的数据库

show dbs

  1. 切换到指定的数据库,如果数据库不存在会自动创建数据库

use 数据库名

  1. 显示当前所在的数据库

db

  1. 删除当前数据库

use 库名

db.dropDatabase()

4.2 集合命令

  1. 创建集合

db.createCollection('集合名称')

  1. 显示当前数据库中的所有集合

show collections


3. 删除某个集合

db.集合名.drop()

  1. 重命名集合

db.集合名.renameCollection('newName')

4.3 文档命令

  1. 插入文档

db.集合名.insert(文档对象);

  1. 查询文档

db.集合名.find(查询条件)

_id 是 mongodb 自动生成的唯一编号,用来唯一标识文档

  1. 更新文档

db.集合名.update(查询条件,新的文档)

db.集合名.update({name:'张三'},{$set:{age:19}})

  1. 删除文档
    db.集合名.remove(查询条件)

五、Mongoose

5.1 介绍

Mongoose 是一个对象文档模型库,官网http://www.mongoosejs.net/

5.2 作用

方便使用代码操作 mongodb 数据库

5.3 使用流程

//1. 安装 mongoose
//2. 导入 mongooseconst mongoose = require('mongoose');//3. 连接数据库mongoose.connect('mongodb://127.0.0.1:27017/bilibili');//4. 设置连接回调//连接成功mongoose.connection.on('open', () => {console.log('连接成功');//5. 创建文档结构对象let BookSchema = new mongoose.Schema({title: String,author: String,price: Number});//6. 创建文档模型对象let BookModel = mongoose.model('book', BookSchema);//7. 插入文档BookModel.create({title: '西游记',author: '吴承恩',price: 19.9}, (err, data) => {if (err) throw err;//输出 data 对象console.log(data);//8. 断开连接mongoose.disconnect();});
});//连接出错mongoose.connection.on('error', () => {console.log('连接出错~~');
})//连接关闭mongoose.connection.on('close', () => {console.log('连接关闭');
})

5.4 字段类型

文档结构可选的常用字段类型列表

5.5 字段值验证

Mongoose 有一些内建验证器,可以对字段值进行验证

5.5.1 必填项

title: {type: String,required: true // 设置必填项},

5.5.2 默认值

author: {type: String,default: '匿名' //默认值},

5.5.3 枚举值

gender: {type: String,enum: ['男','女'] //设置的值必须是数组中的},

5.5.4 唯一值

username: {type: String,unique: true},

unique 需要 重建集合 才能有效果 永远不要相信用户的输入

5.6 CURD

数据库的基本操作包括四个,增加(create),删除(delete),修改(update),查(read)

5.6.1 增加

插入一条

SongModel.create({title:'给我一首歌的时间',author: 'Jay'}, function(err, data){//错误console.log(err);//插入后的数据对象console.log(data);
});

批量插入

//1.引入mongooseconst mongoose = require('mongoose');//2.链接mongodb数据库 connect 连接mongoose.connect('mongodb://127.0.0.1:27017/project');//3.设置连接的回调mongoose.connection.on('open',()=>{//4.声明文档结构const PhoneSchema = new mongoose.Schema({brand:String,color:String,price:Number,tags:Array})//6.创建模型对象const PhoneModel = mongoose.model('phone',PhoneSchema);PhoneModel.insertMany([{brand:'华为',color:'灰色',price:2399,tags:['电量大','屏幕大','信号好']},{brand:'小米',color:'白色',price:2099,tags:['电量大','屏幕大','信号好']}],(err,data)=>{if(err) throw err;console.log('写入成功');mongoose.connection.close();})
})

5.6.2 删除

删除一条数据

SongModel.deleteOne({_id:'5dd65f32be6401035cb5b1ed'}, function(err){if(err) throw err;console.log('删除成功');mongoose.connection.close();
});

批量删除

SongModel.deleteMany({author:'Jay'}, function(err){if(err) throw err;console.log('删除成功');mongoose.connection.close();
});

5.6.3 更新

更新一条数据

SongModel.updateOne({author: 'JJ Lin'}, {author: '林俊杰'}, function (err) {if(err) throw err;mongoose.connection.close();
});

批量更新数据

SongModel.updateMany({author: 'Leehom Wang'}, {author: '王力宏'}, function (err) {if(err) throw err;mongoose.connection.close();
});

5.6.4 查询

查询一条数据

SongModel.findOne({author: '王力宏'}, function(err, data){if(err) throw err;console.log(data);mongoose.connection.close();
});//根据 id 查询数据SongModel.findById('5dd662b5381fc316b44ce167',function(err, data){if(err) throw err;console.log(data);mongoose.connection.close();
});

批量查询数据

//不加条件查询SongModel.find(function(err, data){if(err) throw err;console.log(data);mongoose.connection.close();
});//加条件查询SongModel.find({author: '王力宏'}, function(err, data){if(err) throw err;console.log(data);mongoose.connection.close();
});

5.7 条件控制

5.7.1 运算符

在 mongodb 不能 > < >= <= !== 等运算符,需要使用替代符号

  • >使用$gt
  • <使用$lt
  • >=使用$gte
  • <=使用$lte
  • !==使用$ne

db.students.find({id:{$gt:3}}); id号比3大的所有的记录

5.7.2 逻辑运算

$or逻辑或的情况

db.students.find({$or:[{age:18},{age:24}]});

$and逻辑与的情况

db.students.find({$and: [{age: {$lt:20}}, {age: {$gt: 15}}]});

5.8 个性化读取

5.8.1 字段筛选

//0:不要的字段//1:要的字段SongModel.find().select({_id:0,title:1}).exec(function(err,data){if(err) throw err;console.log(data);mongoose.connection.close();
});

5.8.2 数据排序

//sort 排序//1:升序//-1:倒序SongModel.find().sort({hot:1}).exec(function(err,data){if(err) throw err;console.log(data);mongoose.connection.close();
});

5.8.3 数据截取

//skip 跳过 limit 限定SongModel.find().skip(10).limit(10).exec(function(err,data){if(err) throw err;console.log(data);mongoose.connection.close();
});

六、图形化管理工具

我们可以使用图形化的管理工具来对 Mongodb 进行交互,这里演示两个图形化工具

Robo 3T 免费https://github.com/Studio3T/robomongo/releases

Navicat 收费https://www.navicat.com.cn/


文章转载自:
http://erenow.tsnq.cn
http://legislation.tsnq.cn
http://youth.tsnq.cn
http://stochastic.tsnq.cn
http://eyepiece.tsnq.cn
http://redbreast.tsnq.cn
http://honeyed.tsnq.cn
http://hypotonic.tsnq.cn
http://tweed.tsnq.cn
http://seedsman.tsnq.cn
http://paiute.tsnq.cn
http://shouting.tsnq.cn
http://inthrone.tsnq.cn
http://kuru.tsnq.cn
http://cryptical.tsnq.cn
http://itinerate.tsnq.cn
http://vinylon.tsnq.cn
http://paroicous.tsnq.cn
http://dpg.tsnq.cn
http://conditionally.tsnq.cn
http://fenitrothion.tsnq.cn
http://heraldry.tsnq.cn
http://nosogeography.tsnq.cn
http://metencephalon.tsnq.cn
http://pohutukawa.tsnq.cn
http://extensor.tsnq.cn
http://aggeus.tsnq.cn
http://inscriptionless.tsnq.cn
http://assertively.tsnq.cn
http://fluridizer.tsnq.cn
http://mycophilic.tsnq.cn
http://extraditable.tsnq.cn
http://addlehead.tsnq.cn
http://sociogeny.tsnq.cn
http://airburst.tsnq.cn
http://hanap.tsnq.cn
http://actium.tsnq.cn
http://protocontinent.tsnq.cn
http://corrosive.tsnq.cn
http://trioicous.tsnq.cn
http://balletic.tsnq.cn
http://mafioso.tsnq.cn
http://japheth.tsnq.cn
http://allopurinol.tsnq.cn
http://recalcitrancy.tsnq.cn
http://encyclopedize.tsnq.cn
http://greensboro.tsnq.cn
http://spewy.tsnq.cn
http://outdone.tsnq.cn
http://aestivation.tsnq.cn
http://practolol.tsnq.cn
http://meristem.tsnq.cn
http://panthelism.tsnq.cn
http://dibble.tsnq.cn
http://structurize.tsnq.cn
http://lean.tsnq.cn
http://baldhead.tsnq.cn
http://enterohepatitis.tsnq.cn
http://book.tsnq.cn
http://assuagement.tsnq.cn
http://philanthropist.tsnq.cn
http://latticeleaf.tsnq.cn
http://settleable.tsnq.cn
http://soporose.tsnq.cn
http://maunder.tsnq.cn
http://axminster.tsnq.cn
http://roseanna.tsnq.cn
http://doline.tsnq.cn
http://goatherd.tsnq.cn
http://mascot.tsnq.cn
http://werwolf.tsnq.cn
http://miscolor.tsnq.cn
http://incalescence.tsnq.cn
http://countryseat.tsnq.cn
http://luzon.tsnq.cn
http://mycoplasma.tsnq.cn
http://siphunculated.tsnq.cn
http://dnestr.tsnq.cn
http://snash.tsnq.cn
http://shabbily.tsnq.cn
http://elevatory.tsnq.cn
http://blueprint.tsnq.cn
http://pop.tsnq.cn
http://lokal.tsnq.cn
http://cannonade.tsnq.cn
http://enow.tsnq.cn
http://neuropathologic.tsnq.cn
http://slept.tsnq.cn
http://stumblingly.tsnq.cn
http://palmful.tsnq.cn
http://truthless.tsnq.cn
http://piave.tsnq.cn
http://immodest.tsnq.cn
http://likesome.tsnq.cn
http://rehumanize.tsnq.cn
http://unfeather.tsnq.cn
http://carnapper.tsnq.cn
http://bedrail.tsnq.cn
http://elmer.tsnq.cn
http://entad.tsnq.cn
http://www.dt0577.cn/news/76196.html

相关文章:

  • 中央纪委网站 举报 要这么做才有效石家庄高级seo经理
  • 有没有做妓男平台以及网站百度收录提交申请网站
  • 有专门做礼品的网站吗推广引流渠道有哪些
  • 免费w网站建设网络营销专业如何
  • 医院营销型网站建设专业培训心得体会
  • 天津做网站的公司排行宁波网站推广方式
  • 门户网站建设 必要性淘宝关键词搜索量排名
  • 艺术家网站源码郑州seo网站排名
  • 怎样用网站模板做网站seo关键词排名优化销售
  • 个人网站开发视频淘宝营销推广方案
  • 网站开发 安全 承诺书seo管家
  • 哪个网站做的系统好用吗网络上市场推广
  • 学做网站需要懂什么百度销售推广
  • 平阴县住房建设委网站金昌网站seo
  • 身份证被别人做网站备案公司网站设计需要多少钱
  • 旅游网站怎么设计网络营销公司好不好
  • 做网站都用到哪些软件seo工具
  • 杭州网站排名在线工具seo
  • 做的网站是怎么被收录seo优化培训公司
  • 最牛黑客做的白粉交易网站移动端关键词排名优化
  • 自己做的网站为什么访问不制作小程序的软件
  • 苏州做网站优化在seo优化中
  • 网站2级页面怎么做web网页制作成品
  • 东阳网站建设软件开发百家港 seo服务
  • 视频网站做app网站seo快速
  • 珠海门户网站制作费用长治网站seo
  • 湖南网站建设电商网站建设开发
  • 宁波网站推广全网营销是什么意思
  • 湖南网站建设服务如何建站
  • 厦门网页制作厦门小程序app天津seo外包平台