当前位置:网站首页>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() :会删除当前所在数据库

本次分享就到这,增删改查中的改数据比较麻烦,后续再分享。
边栏推荐
- 【教程】如何让VisualStudio的HelpViewer帮助文档独立运行
- sqoop的表的导入
- [unreal] animation notes of the scene
- Basic notes of illusory AI blueprint (10000 words)
- Blender volume fog
- Notes de base sur les plans illusoires d'IA (triés en 10 000 mots)
- 2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?
- [illusory] weapon slot: pick up weapons
- What is the relationship between realizing page watermarking and mutationobserver?
- Large neural networks may be beginning to realize: the chief scientist of openai leads to controversy, and everyone quarrels
猜你喜欢

Understand the composition of building energy-saving system

Junit5 supports suite methods

Blender ocean production

【MySQL】连接MySQL时出现异常:Connection must be valid and open

Blender camera surround motion, animation rendering, video synthesis

sqoop创建job出现的一系列问题解决方法

UE4夜间打光笔记

MPLS experiment

Edge computing accelerates live video scenes: clearer, smoother, and more real-time

Blender多鏡頭(多機比特)切換
随机推荐
Network communication learning
What wires are suitable for wiring on bread board?
网络通信学习
ICLR 2022: how does AI recognize "things I haven't seen"?
UE illusory engine programmed plant generator setup -- how to quickly generate large forests
SAP Spartacus express checkout design
How much is it to develop a system software in Beijing, and what funds are needed to develop the software
2021-09-12
JS reduce accumulator
【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
sqoop创建job出现的一系列问题解决方法
[illusory] automatic door blueprint notes
[unity3d] cannot correctly obtain the attribute value of recttransform, resulting in calculation error
Project practice, redis cluster technology learning (6)
[Yu Yue education] University Physics (Electromagnetics) reference materials of Taizhou College of science and technology, Nanjing University of Technology
[unreal] key to open the door blueprint notes
Basic notes of illusory AI blueprint (10000 words)
Database -- acid of transaction -- introduction / explanation
虚幻AI蓝图基础笔记(万字整理)
[IDL] Research