IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

MongoDB创建与删除集合(collection)

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

110_1.png

(一)创建集合

MongoDB的集合相当于关系型数据库的表,不过在创建集合时,执行指定集合名称与选项即可,无需指定类似RDBMS的列名。

创建集合的语法为:

db.createCollection(name,option)

其中,name是集合的名称,option是集合的配置选项。option参数是可选的,可以使用以下参数:

字段 类型 描述
capped Boolean 如果为true,则启用封闭的集合,上限是固定大小的集合,在到达最大大小时自动覆盖最旧的条目。如果指定为true。则还需指定size参数
autoIndexId Boolean 如果为true,则在_id列自动创建索引
size 数字 指定上限集合的最大尺寸(以字节为单位),与capped配合使用
max 数字 指定上限集合中允许的最大文档数

备注:在插入文档时,先检查上限集合capped字段size大小,然后再检查max字段。

例子1 : 创建集合mycoll

> use lijiamandb
switched to db lijiamandb
> db.createCollection("mycoll");
{ "ok" : 1 }
> 
> 
> show collections;
mycoll

例子2 :创建集合mycoll2,设置文档上限为100M,最大文档个数为10000。

> db.createCollection("mycoll2",{capped:true,autoIndexId:true,size:104857600,max:100})
{
    "note" : "the autoIndexId option is deprecated and will be removed in a future release",
    "ok" : 1
}

备注:autoIndexId是过时参数,后面将被移除,尽量别用。

除了上面使用db.createCollection(name,option)方法创建集合外,还可以在插入文档时直接创建集合:

> db.mycoll3.insert({"name":"test"});
WriteResult({ "nInserted" : 1 })
> show collections;
mycoll
mycoll2
mycoll3

(二)删除集合

删除集合的语法为:

db.<connection_name>.drop()

例子 : 删除集合mycoll3

> show collections
mycoll
mycoll2
mycoll3

> db.mycoll3.drop()
true

> show collections
mycoll
mycoll2

如果删除成功,drop()方法将返回true,否则返回false。

【完】

文章永久链接:https://tech.souyunku.com/?p=35440


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(99) 打赏



未经允许不得转载:搜云库技术团队 » MongoDB创建与删除集合(collection)

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367