zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

MongoDB 创建集合详解数据库

MongoDB数据库集合 详解 创建
2023-06-13 09:20:09 时间
createCollection() 方法

MongoDB db.createCollection(name, options) 是用来创建集合.

基本的 createCollection() 命令语法如下:

db.createCollection(name, options)

在命令中, name 是要创建的集合的名称. Options 是一个文件,用于指定配置的集合


Boolean (可选)如果为true,则启用封顶集合。封顶集合是固定大小的集合,会自动覆盖最早的条目,当它达到其最大大小。如果指定true,则需要也指定尺寸参数。

下面的例子显示了几个重要的选项 createCollection()方法的语法:

 db.createCollection("person", { capped : true, autoIndexID : true, size : 6142800, max : 10000 } ) 

{ "ok" : 1 } 

 

在MongoDB中,不需要创建集合。当插入一些文件 MongoDB 自动创建的集合。

 db.article.insert({

 "title" : "hellomonogo"}) 

 show collections 

ithome 

person 

article 

 

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/4204.html

MongoDB