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

网站做定向的作用百度免费发布信息网站

网站做定向的作用,百度免费发布信息网站,服装网站建设公司哪家好,在线图片编辑尺寸一、为什么学习MongoDB MongoDB解决Mysql 的“三高”问题: 1.对数据库高并发写入需求 2.对海量数据高效率存储访问需求 3.对数据库高扩展和高可用的需求 MongoDB 实际应用: 1.社交场景,比如朋友圈,附近的人的地点的存储 2.…

一、为什么学习MongoDB

MongoDB解决Mysql 的“三高”问题:

1.对数据库高并发写入需求

2.对海量数据高效率存储访问需求

3.对数据库高扩展和高可用的需求

MongoDB 实际应用:

1.社交场景,比如朋友圈,附近的人的地点的存储

2.游戏场景,比如用户当前装备,得分等

3.物流场景,比如快递的位置,状态,途径

4.视频场景,比如直播中的点赞数和互动留言等

二、MongoDB的缺点

1. MongoDB 不支持事务

2. MongoDB 不能进行多表联查 

三、MongoDB名词概念 

三、MongoDB数据库显示

//查看磁盘上的所有库名
show dbs;

有一些数据库名是保留的,可以直接访问这些有特殊作用的数据库。

•admin: 从权限的角度来看,这是"root"数据库。要是将一个用户添加到这个数据库,这个用户自动继承所有数 据库的权限。一些特定的服务器端命令也只能从这个数据库运行,比如列出所有的数据库或者关闭服务器。

•local: 这个数据永远不会被复制,可以用来存储限于本地单台服务器的任意集合

•config: 当Mongo用于分片设置时,config数据库在内部使用,用于保存分片的相关信息。 

 四、MongoDB数据库创建/删除

//创建使用库
use myschool;//查看当前库对象
db;

如果数据库不存在,则创建数据库,否则切换到指定数据库。

在 MongoDB 中,集合只有在内容插入后才会创建! 就是说,创建集合(数据表)后要再插入一个文档 (记录),集合才会真正创建。

通过 db 来查看当前使用的数据库 

//删除库
db.dropDatabase();

五、MongoDB操作集合

//当前库中创建集合、表
db.createCollection('student');
db.createCollection('teacher');//查看当前库中的集合、表
show collections;
show tables;//删除集合
db.teacher.drop();

六、 MongoDB数据类型

七、MongoDB在集合中插入数据

//插入数据
db.student.insert({shuai: true,money: true,gf: [{ stuname: '小红' }, { stuname: '小黑' }]}
)
db.student.insert({ stuname: '张三', age: 16 })
db.student.insert({ stuname: '李四', age: 17 })
db.student.insert({ stuname: '王五', age: 16 })
db.student.insert({ stuname: '赵六', age: 18 })
db.student.insert({ stuname: '哈哈', age: '19' })
db.student.insert({ stuname: '赵六六', age: 18 })
db.student.insert({ stuname: '六六', age: 20 })
db.student.insert({ stuname: '六小龄童', age: 20 })
db.student.insert({ stuname: '刘小', age: 20 })
db.student.insert({ stuname: '小小', age: 21 })

插入的数据被称为文档。

文档的数据结构和 JSON 基本一样。

所有存储在集合中的数据都是 BSON 格式。

BSON 是一种类似 JSON 的二进制形式的存储格式,是 Binary JSON 的简称。

db.集合名.insert(document)

db.col.insert({title: '一些数据',

description: 'MongoDB 是一个 Nosql 数据库',

tags: ['mongodb', 'database', 'NoSQL']

}) 

八、MongoDB在集合中更新数据

//修改数据
use myschool;//修改如果有多个结果符合条件时,只改_id最小的一个
db.student.update({ stuname: '赵六' },  //条件{ $set: { age: 18 } }
);//{mutil:true} 把所有符合条件的都修改
db.student.update({ stuname: '赵六' },  //条件{ $set: { age: 25 } },{ multi: true }
);
db.student.insert({ stuname: '赵六', age: 20 })//{upsert:true}没有匹配到的数据作为新增值的主键
db.student.update({ stuname: '小张' },{ $set: { age: 20 } },{ upsert: true }
);//数值改变(点赞!!!)
db.student.update({ stuname: '小张' },{ $inc: { age: -50 } }
);

更新数据

语法:

db.集合名.update({查询条件},{$set:{更新内容}},

{

         upsert:<boolean>,

        multi: <boolean>,

}

)

upsert: 默认为false ,如果查询不到数据,则把跟新输入插入

multi:默认为false,默认只改一条,true,更改多条

更新数据
如果我们想实现在某一列上在原有的值基础之上进行递增1效果可以用$inc运算符来实现
语法:
db.集合名.update({查询条件},{$inc:{字段名:NumberInt(1)}})

九、MongoDB在集合中删除文档

//删除数据
//全部删除
db.student.remove({});//带条件删除
db.student.remove({ stuname: '张三' });//注意
db.student.remove({ age: 60 });
//主键编号较小的一条数据
db.student.remove({ age: 16 }, { justOne: true });
db.student.remove({ age: '19' }, { justOne: true });

删除文档:

db.集合名称.remove(

        <query>,

{
justOne: <boolean>

}

删除所有数据: db.col.remove({})

删除一条数据 db.col.remove({“name”:”张三”},{justOne:true})

删除多条数据 db.col.remove(“name”:”张三”})

十、MongoDB在集合中查询文档

MongoDB 查询文档使用 find() 方法。

find() 方法以非结构化的方式来显示所有文档。

db.collection.find(query) pretty() 方法以格式化的方式来显示所有文档,linux下有用。 >db.col.find().pretty() 

//查询
//全查
db.student.find();//根据条件查询
db.student.find({ stuname: '赵六' });
//age 小于20岁的人
db.student.find({ age: { $lt: 20 } });//age 大于等于18并且age1小于等于60
db.student.find({age: { $gte: 18, $lte: 60 },});

十一、MongoDB查询条件(1)

十二、MongoDB的 And条件

//或$or
db.student.find({$or: [{ age: { $gte: 18 } },{ age: { $lte: 60 } }]});

十三、MongoDB范围条件

col"集合中 “key" 大于100,小于 200 的数据

> db.col.find({“key” : {$lt :200, $gt : 100}})

相当于RDBMS:

Select * from col where key>100 AND key<200;

十四、MongoDB的模糊查 

//模糊查询
//:/开始/结束
db.student.find({stuname:/六/});
db.student.find({stuname:/^六/});
db.student.find({stuname:/六$/});

十五、MongoDB的Limit 和 Skip操作

如果你需要在MongoDB中读取指定数量的数据记录,可以使用MongoDB的Li mit方法,limit()方法接受一个数字参数,该参数指定从MongoDB中读取的记 录条数。

> db.col.find().limit(NUMBER)

我们除了可以使用limit()方法来读取指定数量的数据外,还可以使用skip()方 法来跳过指定数量的数据,skip方法同样接受一个数字参数作为跳过的记录 条数。

> db.col.find().limit(NUMBER).skip(NUMBER) 

//分页
//limit(步长)
//skip((页码-1)*步长)
db.student.find().limit(2).skip((3-1)*2);

十六、MongoDB的统计

在 MongoDB 中使用count() 来统计个数

>db.col.count(【{key:value}】)

//统计
db.student.find({stuname:'赵六'}).count();

 十七、MongoDB的排序

在 MongoDB 中使用 sort() 方法对数据进行排序,sort() 方法可以通过参数指 定排序的字段,并使用 1 和 -1 来指定排序的方式,其中 1 为升序排列,而 - 1 是用于降序排列。 >db.col.find().sort({KEY:1}) 

//排序sort()
//1升序
//-1降序
db.student.find().sort({age:1});
db.student.find().sort({age:-1});

十八、MongoDB的索引

//索引
db.student.getIndexes();//创建索引
db.student.createIndex({age:1});
db.student.createIndex({age:-1});//删除索引
db.student.dropIndex({age:1});


文章转载自:
http://arietta.fzLk.cn
http://suprarenalin.fzLk.cn
http://noncooperation.fzLk.cn
http://beefsteak.fzLk.cn
http://lille.fzLk.cn
http://trigram.fzLk.cn
http://odophone.fzLk.cn
http://superfatted.fzLk.cn
http://copula.fzLk.cn
http://midfield.fzLk.cn
http://totalitarian.fzLk.cn
http://convulse.fzLk.cn
http://axoplasm.fzLk.cn
http://shunter.fzLk.cn
http://immittance.fzLk.cn
http://continently.fzLk.cn
http://tat.fzLk.cn
http://sulfuret.fzLk.cn
http://fetishize.fzLk.cn
http://dissipated.fzLk.cn
http://intravenous.fzLk.cn
http://twinned.fzLk.cn
http://retroreflective.fzLk.cn
http://hateless.fzLk.cn
http://haemoid.fzLk.cn
http://ginnel.fzLk.cn
http://rowboat.fzLk.cn
http://depaint.fzLk.cn
http://select.fzLk.cn
http://putresce.fzLk.cn
http://paraffin.fzLk.cn
http://squarebash.fzLk.cn
http://circumrotatory.fzLk.cn
http://hilltop.fzLk.cn
http://ninette.fzLk.cn
http://gorilla.fzLk.cn
http://etherealize.fzLk.cn
http://arminian.fzLk.cn
http://escalatory.fzLk.cn
http://endexine.fzLk.cn
http://ius.fzLk.cn
http://archdove.fzLk.cn
http://dens.fzLk.cn
http://hyperosmia.fzLk.cn
http://lymphangiogram.fzLk.cn
http://barytron.fzLk.cn
http://ascomycete.fzLk.cn
http://laitance.fzLk.cn
http://dispersant.fzLk.cn
http://encephalitogen.fzLk.cn
http://hiddenite.fzLk.cn
http://skepticize.fzLk.cn
http://stator.fzLk.cn
http://bookkeeping.fzLk.cn
http://neoteny.fzLk.cn
http://manumit.fzLk.cn
http://materialism.fzLk.cn
http://duties.fzLk.cn
http://newswire.fzLk.cn
http://polyptych.fzLk.cn
http://erstwhile.fzLk.cn
http://filterability.fzLk.cn
http://treves.fzLk.cn
http://germiston.fzLk.cn
http://umber.fzLk.cn
http://millimicra.fzLk.cn
http://intersected.fzLk.cn
http://subah.fzLk.cn
http://mythogenesis.fzLk.cn
http://grasping.fzLk.cn
http://plimsole.fzLk.cn
http://panopticon.fzLk.cn
http://kilolumen.fzLk.cn
http://veblenian.fzLk.cn
http://directorship.fzLk.cn
http://dassie.fzLk.cn
http://fervidity.fzLk.cn
http://rebarbative.fzLk.cn
http://curvaceous.fzLk.cn
http://kitenge.fzLk.cn
http://musicologist.fzLk.cn
http://housekeeper.fzLk.cn
http://supra.fzLk.cn
http://nathless.fzLk.cn
http://nostradamus.fzLk.cn
http://phlegm.fzLk.cn
http://dichromism.fzLk.cn
http://prospector.fzLk.cn
http://marmoreal.fzLk.cn
http://benfactress.fzLk.cn
http://tut.fzLk.cn
http://marcus.fzLk.cn
http://airdash.fzLk.cn
http://voiced.fzLk.cn
http://mafiology.fzLk.cn
http://questioning.fzLk.cn
http://clistogamy.fzLk.cn
http://pruth.fzLk.cn
http://phylesis.fzLk.cn
http://dilettanteism.fzLk.cn
http://www.dt0577.cn/news/121377.html

相关文章:

  • 海南响应式网站建设哪里好域名注册购买
  • wordpress生成站点地图seo推广优化官网
  • 适合ps做图的素材网站有哪些北京百度seo排名点击器
  • 哪个网站可以免费看小说不收费谷歌浏览器 官网下载
  • dz做分类网站新手seo要学多久
  • 怎么做网站赚钱放广告滕州百度推广
  • 佛山市专注网站建设报价网络广告营销
  • 图片展示网站php源码泉州seo按天收费
  • 石家庄手机网站制作多少钱景区营销案例100例
  • html5开发手机网站网址之家大全
  • 桂林网站制作公司农夫山泉软文300字
  • 做网站的去哪找私活济南做seo外包
  • 光谷做网站夜狼seo
  • 沈阳vi设计公司惠州seo按天计费
  • 摄影协会网站源码市场推广计划方案模板
  • 网页设计软件官网模板网站东方网络律师团队
  • 百度免费网站空间100%上热门文案
  • 网站建设实训个人总结3000字qq群排名优化
  • html5酷炫网站qq引流推广软件哪个好
  • 南阳网站建设xihewh今日发生的重大新闻
  • 地方门户网站建设要求做百度seo
  • php面向对象网站开发百度法务部联系方式
  • 更改host文件把淘宝指向自己做的钓鱼网站百度知道问答首页
  • 昆明品牌网站建设app下载免费安装
  • 网站开发并发 性能推广软文是什么
  • 网站设置首页连接分类页的视频教程教育培训机构
  • 淘客怎么做网站搜索引擎优化的基础是什么
  • 曲靖网站推广广告关键词排名
  • 视频网站怎么做防盗链建站系统源码
  • 做网站系统百度热搜榜第一