导读:MongoDB是一款非关系型数据库,支持动态schema设计和高度可扩展性 。在使用MongoDB时,新建表是一个基础操作 。本文将介绍如何在MongoDB中新建表 。
1. 连接MongoDB
在命令行中输入mongo命令,连接到MongoDB实例 。
2. 选择数据库
使用use命令选择要创建表的数据库 。如果该数据库不存在,则会自动创建 。
3. 新建集合
使用db.createCollection()命令创建集合,其中参数为集合名称和选项 。例如,创建名为“users”的集合:
```
db.createCollection("users", {
validator: { $jsonSchema: {
bsonType: "object",
required: [ "name", "age", "email" ],
properties: {
name: {
bsonType: "string",
description: "must be a string and is required"
},
age: {
bsonType: "int",
minimum: 18,
maximum: 100,
description: "must be an integer in [18, 100] and is required"
email: {
bsonType : "string",
pattern: "@mongodb\.com$",
description: "must be a string and match the regular expression pattern"
}
}
} }
})
4. 查看集合
使用show collections命令查看已创建的集合 。
【mongodb如何创建表 mongodb新建表】总结:本文介绍了如何在MongoDB中新建表 , 包括连接MongoDB、选择数据库、新建集合等步骤 。通过学习本文,读者可以掌握MongoDB基础操作中的新建表技能 。
- 如何使用cmd命令行提示符登录mysql服务器 cmd中登陆mysql
- 如何修改戴尔服务器的IP地址? 戴尔服务器ip地址怎么改
- mongodb 更新子文档 mongodb数据文件无法新建
- 客户端无法连接到异速联服务器 客户端无法连接mongodb
- mongodb大公司案例 MongoDB公司怎么样
- mongodb查看数据库大小 查看mongodb集群容量
- 无法启动mongodb 1053 安装mongodb显示没有启动权
- mongodb用来存储什么 mongodb适合存储对象吗
- 2021年高考最热作文 mysql创建实例用户
- mysql创建数据表时指定字符集 mysql有符号创建
