ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
**查看当前Database所有的Collection** ```sql -- 使用 show collections 或者 show tables > show collections event_db > show tables event_db ``` **方式1:显示创建集合** ```sql 语法:db.createCollection(name, options) ``` | 参数 | 默认值 | 说明 | | --- | --- | --- | | name | | 创建的集合名称 | :-: options是可选参数,它的可选项如下 | 参数 | 默认值 | 说明 | | --- | --- | --- | | capped| false | 如果为 true,则创建固定集合。固定集合是指有着固定大小的集合,当达到最大值时,它会自动覆盖最早的文档。当该值为 true 时,必须指定 size 参数。 | | autoIndexId | false | 如为 true,自动在 _id 字段创建索引。默认为false。 | | size | 整数 | 为固定集合指定一个最大值,以千字节计(KB)。如果 capped 为 true,也需要指定该字段。 | | max | 整数 | 指定固定集合中包含文档的最大数量。 | ```sql > db.createCollection( ... "mycol", ... { ... capped: true, ... autoIndexId: true, ... size: 6142800, ... max: 10000 ... } ... ) {"ok" : 1} ``` **方式2:隐式创建集合** ```sql > db.collectName.insert({"name": "employee"}) WriteResult({ "nInserted" : 1 }) ``` **删除Collection** ```sql > db.collectName.drop() true ```