当前位置:网站首页>MongoDB-快速上手MongoDB命令行的一些简单操作
MongoDB-快速上手MongoDB命令行的一些简单操作
2022-07-02 06:36:00 【小博测试成长之路】
在MongoDB里面,数据库下面的表我们一般用集合collections去描述。
在mongo里面,数据库和表也可以不写创建语句。
常见命令用法如下:
1
展示所有数据库
show dbs
2
进入到某个数据库,然后去执行一些建表的操作
use 数据库名
数据库如果不存在的话,再后面执行其他操作,比如往表里面插入数据,会自动创建数据库
从上图可以看出:本来是不存在study数据库的,但是使用use study数据库,并且在里面往某张表插入一条数据之后,会自动的创建表以及数据库。
db.createCollection("表名")
3
显示某个数据库下的所有的表
show tables / show collections:显示数据库下所有的表
4
往表里面插入数据
db.集合名称.insert(文档对象);
db.user.insert({"age":30,"name":"小博"});
从上图可以看到,insert()方法其实是已经不推荐使用了,建议使用insertOne, insertMany, 或者 bulkWrite方法。
使用用法参考:
db.user.insertOne({"age":30,"name":"小博1"});
db.user.insertMany([{"age":30,"name":"小博2"} ,{"age":30,"name":"小博3 "}]);
效果如下:
bulkWrite用法比较复杂,等后面再演示。
5
删除表
db.集合名称.drop()
6
清空表里面的数据
db.集合名称.remove({})
7
查询
db.集合名称.find({})
查询有很多复杂的用法,后面再详细的介绍
8
删除数据库
use db名字
db.dropDatabase() :会删除当前所在数据库
本次分享就到这,增删改查中的改数据比较麻烦,后续再分享。
边栏推荐
- How to achieve the top progress bar effect in background management projects
- 2837xd code generation module learning (2) -- ADC, epwm module, timer0
- sqoop创建job出现的一系列问题解决方法
- Leetcode -- the nearest common ancestor of 236 binary tree
- 快速做出原型
- [MySQL] an exception occurs when connecting to MySQL: connection must be valid and open
- VLAN experiment
- pytest框架实现前后置
- Nonlinear optimization: establishment of slam model
- Understand the composition of building energy-saving system
猜你喜欢
Blender模型导入ue、碰撞设置
虛幻AI藍圖基礎筆記(萬字整理)
Blender多镜头(多机位)切换
What is the relationship between realizing page watermarking and mutationobserver?
Post disaster reconstruction -- Floyd thought
[ue5] two implementation methods of AI random roaming blueprint (role blueprint and behavior tree)
Flink实时计算topN热榜
ue虛幻引擎程序化植物生成器設置——如何快速生成大片森林
This article takes you to learn in detail what is fiber to home FTTH
ICLR 2022: how does AI recognize "things I haven't seen"?
随机推荐
How does {} prevent SQL injection? What is its underlying principle?
AutoCAD - layer Linetype
Large neural networks may be beginning to realize: the chief scientist of openai leads to controversy, and everyone quarrels
pytest框架实现前后置
Vscode set JSON file to format automatically after saving
ERROR 1118 (42000): Row size too large (> 8126)
[IDL] Research
Blender model import UE, collision settings
Flink实时计算topN热榜
Applet development summary
Blender模型导入ue、碰撞设置
Blender volume fog
ue虛幻引擎程序化植物生成器設置——如何快速生成大片森林
虚幻材质编辑器基础——如何连接一个最基本的材质
Centos7 one click compilation and installation of PHP script
flink 提交程序
【Unity3D】制作进度条——让Image同时具有Filled和Sliced的功能
Basic notes of illusory AI blueprint (10000 words)
MPLS experiment
Leetcode -- the nearest common ancestor of 236 binary tree