当前位置:网站首页>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() :会删除当前所在数据库
本次分享就到这,增删改查中的改数据比较麻烦,后续再分享。
边栏推荐
- Webui automated learning
- Centos7 one click compilation and installation of PHP script
- 【MySQL】连接MySQL时出现异常:Connection must be valid and open
- ue虛幻引擎程序化植物生成器設置——如何快速生成大片森林
- Following nym, the new project Galaxy token announced by coinlist is gal
- Brief analysis of edgedb architecture
- Project practice, redis cluster technology learning (12)
- JS reduce accumulator
- Sil/pil test of matlab code generation
- [unity3d] nested use layout group to make scroll view with dynamic sub object height
猜你喜欢
Pytest framework implements pre post
Large neural networks may be beginning to realize: the chief scientist of openai leads to controversy, and everyone quarrels
Post disaster reconstruction -- Floyd thought
07数据导入Sqoop
[visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened
This monitoring system makes workers tremble: turnover intention and fishing can be monitored. After the dispute, the product page has 404
Determine whether there are duplicate elements in the array
测试--面试题总结
Tee command usage example
两数之和,求目标值
随机推荐
Spatial interpretation | comprehensive analysis of spatial structure of primary liver cancer
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
Allure -- common configuration items
pytest框架实现前后置
Flink实时计算topN热榜
Notes de base sur les plans illusoires d'IA (triés en 10 000 mots)
Project practice, redis cluster technology learning (10)
ue虚幻引擎程序化植物生成器设置——如何快速生成大片森林
Tee command usage example
What is the relationship between realizing page watermarking and mutationobserver?
How much is it to develop a system software in Beijing, and what funds are needed to develop the software
【Unity3D】制作进度条——让Image同时具有Filled和Sliced的功能
Network real-time video streaming based on OpenCV
Blender model import UE, collision settings
Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
2021-10-02
UE5——AI追逐(藍圖、行為樹)
Sum the two numbers to find the target value
Basic notes of illusory AI blueprint (10000 words)
Centos7 one click compilation and installation of PHP script