当我在集合上创建索引时,结果文档的一个属性是createCollectionAutomatically:false.
db.myCollection.createIndex({"address":1})
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 3,
"ok" : 1
}
Run Code Online (Sandbox Code Playgroud)
这是什么意思,什么时候是真的?
在这里找到答案: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)
| 归档时间: |
|
| 查看次数: |
2306 次 |
| 最近记录: |