createdCollection自动意味着什么?

Ger*_*cke 3 mongodb

当我在集合上创建索引时,结果文档的一个属性是createCollectionAutomatically:false.

db.myCollection.createIndex({"address":1})
{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 2,
    "numIndexesAfter" : 3,
    "ok" : 1
}
Run Code Online (Sandbox Code Playgroud)

这是什么意思,什么时候是真的?

Ger*_*cke 9

在这里找到答案:https://docs.mongodb.com/manual/reference/command/createIndexes/#output

createdCollectionAutomatically表示如果操作创建一个集合.如果集合不存在,MongoDB将创建集合作为索引操作的一部分.

因此,当我运行db.myCollection.createIndex({"address":1})并且myCollection不存在时,结果是

{
    "createdCollectionAutomatically" : true,
    "numIndexesBefore" : 1,
    "numIndexesAfter" : 2,
    "ok" : 1
}
Run Code Online (Sandbox Code Playgroud)

  • 引用的链接不再存在。`404`。我正在将链接更改为 mongoDB 文档中的正确参考。 (2认同)