当前位置:网站首页>MongoDB是什么,怎么用?
MongoDB是什么,怎么用?
2022-08-08 10:09:00 【51CTO】
MongoDB是一款为web应用程序和互联网基础设施设计的数据库管理系统,简单来说,MongoDB就是数据库,是NoSQL类型的数据库。那么,我们要怎么使用MongoDB呢?
1.切换数据库
use dba
2.插入语法
(1)db.users.insert({username:"smith"})
(2)db.users.save({username:"smith"})
3.查找语法
(1)db.users.find()
(2)db.users.count()
4.更新语法
(1)db.users.update({username:"smith"},{$set:{country:"Canada"}}) ;
(2)//把用户名为smith的用户的国家改成Canada ;
(3)db.users.update({username:"smith"},{$unset:{country:1}}) ;
(4)//把用户名为smith的用户的国家字段给移除 ;
(5)db.users.update({username:"jones"},{$set:{favorites:{movies:
["casablance","rocky"]}}}) ;
(6)//这里主要体现多值修改,在favorties字段中添加多个值 ;
(7)db.users.update({"favorites.movies":"casablance"},{$addToSet:{favorites.
movies:"the maltese"}},false,true)
(8)//多项更新
5.删除语法
(1)db.foo.remove() //删除所有数据
(2)db.foo.remove({favorties.cities:"cheyene"}) //根据条件进行删除
(3)db.drop() //删除整个集合
6.索引相关语法
(1)db.numbers.ensureIndex({num:1})
(2)//创建一个升序索引
(3)db.numbers.getIndexes()
(4)//获取全部索引
7.基本管理语法
(1)show dbs ;
(2)//查询所有数据库 ;
(3)show collections ;
(4)//显示所有表 ;
(5)//显示数据库状态信息;
(6)db.numbers.stats() ;
(7)//显示集合表状态信息 ;
(8)db,shutdownServer() ;
(9)//停止数据库 ;
(10)db.help() ;
(11)//获取数据库操作命令 ;
(12)db.foo.help();
(13)//获取表操作命令 ;
(14)tab 键 //能自动帮我们补全命令
边栏推荐
- NoSQL数据库有哪些优势吗?又有哪些劣势呢?
- mysql 性能分析
- 持久化键值数据库的数据是保存在内存中吗?
- vs2019+boost library (boost_1_67_0) installation
- 【Collection】3. Wallpaper collection
- Feign应用及源码剖析
- In ASP.NET Core 2.0, solve the configuration problem of large file upload
- 使用.NET简单实现一个Redis的高性能克隆版(三)
- "Inversion of Control" and "Dependency Inversion", can't you tell the difference?
- 键值数据库是将什么作为标识符的呢?
猜你喜欢
go调度原理
Loadrunner12.0.2 installation and Chinese language pack installation (Chinese)
简单混合运算计算器
2022 world conference on robots is holding, intelligent robot booster to intelligent, digital transformation and upgrading traditional industry
Feign应用及源码剖析
面试突击72:输入URL之后会执行什么流程?
面试突击72:输入URL之后会执行什么流程?
Mobile/Embedded-CV Model-2017: MobelNets-v1
Multi-scalar multiplication: state of the art & new ideas
VMWare Esxi 虚拟系统数据存储扩容(增加容量)的简明教程
随机推荐
Dubins曲线学习笔记及相关思考
【数学知识】—— 质数/约数
nacos安装
To make people's consumption safer, more assured and more satisfied
mysql 性能分析
典型的NoSQL数据库有哪些呢?
MySQL学习第一部分:认识MySQL
Detailed Explanation of Gradient Vanishing and Gradient Explosion Problems
「控制反转」和「依赖倒置」,傻傻分不清楚?
文档数据库中的文档可以有相同的数据结构嘛?
oracle中联表相关思考
持久化键值数据库的数据是保存在内存中吗?
人大金仓数据库登录、查看数据库
Pinia(一)初体验快速安装与上手
What is intrinsic safety?
Loadrunner的录制event为0的问题解决方法与思路
分门别类输入输出,Go lang1.18入门精炼教程,由白丁入鸿儒,go lang基本数据类型和输入输出EP03
Feign application and source code analysis
继承关系下构造方法的访问特点:
01-MQ介绍以及产品比较