繁体   English   中英

MongoDB:createCollection 带参数

[英]MongoDB:createCollection with parameters

我用了这个评论

> db.createCollection("naveen",{capped:true,autoIndexId:true,size:53440099,max:1000});

我得到了这个:

{
    "note" : "the autoIndexId option is deprecated and will be removed in a future release",
    "ok" : 1
}

删除autoIndexId参数将删除响应中的note

从 MongoDB 3.2 版开始, autoIndexId参数在使用createCollection时已弃用,因此您将收到此note消息以及ok值,以提醒您注意这一点。

autoIndexId参数在 3.4 版本中被删除。

对以下评论的回复在此答案中很有用:

并用什么代替?

看看这个 SO answerMongoDB 文档MongoDB 的 JIRA似乎他们正在推动开发人员不要干预自动索引。

其实MongoDB不需要创建集合,当你插入文档的时候MongoDB会自动为你创建一个集合,并且还会为每个文档生成唯一的Id!

例子:

db.createCollection("naveen",{capped:true,autoIndexId:true,size:53440099,max:1000}); //don't

你不需要创建一个集合,你只需要插入一个直接的文档,它不像SQL,它是JSON。

{ name: 'john', ...}

像这样,在不创建集合的情况下插入文档,它会自动为您生成一个集合!

db.newYear.insert({ name: 'john', age: 33, year: 2020 });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM